ucar.unidata.io.RandomAccessFile.readToByteChannel()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中ucar.unidata.io.RandomAccessFile.readToByteChannel方法的一些代码示例,展示了RandomAccessFile.readToByteChannel的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RandomAccessFile.readToByteChannel方法的具体详情如下:
包路径:ucar.unidata.io.RandomAccessFile
类名称:RandomAccessFile
方法名:readToByteChannel

RandomAccessFile.readToByteChannel介绍

[英]Read nbytes bytes, at the specified file offset, send to a WritableByteChannel. This will block until all bytes are read. This uses the underlying file channel directly, bypassing all user buffers.
[中]在指定的文件偏移量处读取nbytes字节,并发送到可写的ByTechannel。这将阻塞,直到读取所有字节。这将直接使用底层文件通道,绕过所有用户缓冲区。

代码示例

代码示例来源:origin: Unidata/thredds

public long writeCurrentMessage( WritableByteChannel out) throws IOException {
 long nbytes = lastPos - startPos;
 return  raf.readToByteChannel(out, startPos, nbytes);
}

代码示例来源:origin: edu.ucar/bufr

public long writeCurrentMessage( WritableByteChannel out) throws IOException {
 long nbytes = lastPos - startPos;
 return  raf.readToByteChannel(out, startPos, nbytes);
}

代码示例来源:origin: Unidata/thredds

private long readRecordData(ucar.nc2.Structure s, Section section, WritableByteChannel out) throws java.io.IOException, InvalidRangeException {
 long count = 0;
 /* RegularIndexer index = new RegularIndexer( s.getShape(), recsize, recStart, section, recsize);
 while (index.hasNext()) {
   Indexer.Chunk chunk = index.next();
   count += raf.readBytes( out, chunk.getFilePos(), chunk.getNelems() * s.getElementSize());
  }  */
 // LOOK this is the OTW layout based on netcdf-3
 // not sure this works but should give an idea of timing
 Range recordRange = section.getRange(0);
 /* int stride = recordRange.stride();
 if (stride == 1) {
  int first = recordRange.first();
  int n = recordRange.length();
  if (false) System.out.println(" read record " + first+" "+ n * header.recsize+" bytes ");
  return raf.readToByteChannel(out, header.recStart + first * header.recsize, n * header.recsize);
 } else {  */
 for (int recnum : recordRange) {
   if (debugRecord) System.out.println(" read record " + recnum);
   raf.seek(header.recStart + recnum * header.recsize); // where the record starts
   count += raf.readToByteChannel(out, header.recStart + recnum * header.recsize, header.recsize);
  }
 // }
 return count;
}

代码示例来源:origin: edu.ucar/netcdf

private long readRecordData(ucar.nc2.Structure s, Section section, WritableByteChannel out) throws java.io.IOException, InvalidRangeException {
 long count = 0;
 /* RegularIndexer index = new RegularIndexer( s.getShape(), recsize, recStart, section, recsize);
 while (index.hasNext()) {
   Indexer.Chunk chunk = index.next();
   count += raf.readBytes( out, chunk.getFilePos(), chunk.getNelems() * s.getElementSize());
  }  */
 // LOOK this is the OTW layout based on netcdf-3
 // not sure this works but should give an idea of timing
 Range recordRange = section.getRange(0);
 int stride = recordRange.stride();
 if (stride == 1) {
  int first = recordRange.first();
  int n = recordRange.length();
  if (false) System.out.println(" read record " + first+" "+ n * header.recsize+" bytes ");
  return raf.readToByteChannel(out, header.recStart + first * header.recsize, n * header.recsize);
 }  else {
  for (int recnum = recordRange.first(); recnum <= recordRange.last(); recnum += recordRange.stride()) {
   if (debugRecord) System.out.println(" read record " + recnum);
   raf.seek(header.recStart + recnum * header.recsize); // where the record starts
   count += raf.readToByteChannel(out, header.recStart + recnum * header.recsize, header.recsize);
  }
 }
 return count;
}

代码示例来源:origin: edu.ucar/cdm

private long readRecordData(ucar.nc2.Structure s, Section section, WritableByteChannel out) throws java.io.IOException, InvalidRangeException {
 long count = 0;
 /* RegularIndexer index = new RegularIndexer( s.getShape(), recsize, recStart, section, recsize);
 while (index.hasNext()) {
   Indexer.Chunk chunk = index.next();
   count += raf.readBytes( out, chunk.getFilePos(), chunk.getNelems() * s.getElementSize());
  }  */
 // LOOK this is the OTW layout based on netcdf-3
 // not sure this works but should give an idea of timing
 Range recordRange = section.getRange(0);
 int stride = recordRange.stride();
 if (stride == 1) {
  int first = recordRange.first();
  int n = recordRange.length();
  if (false) System.out.println(" read record " + first+" "+ n * header.recsize+" bytes ");
  return raf.readToByteChannel(out, header.recStart + first * header.recsize, n * header.recsize);
 }  else {
  for (int recnum = recordRange.first(); recnum <= recordRange.last(); recnum += recordRange.stride()) {
   if (debugRecord) System.out.println(" read record " + recnum);
   raf.seek(header.recStart + recnum * header.recsize); // where the record starts
   count += raf.readToByteChannel(out, header.recStart + recnum * header.recsize, header.recsize);
  }
 }
 return count;
}

代码示例来源:origin: edu.ucar/cdm

while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 2 * chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 4 * chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 8 * chunk.getNelems());

代码示例来源:origin: edu.ucar/netcdf

while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 2 * chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 4 * chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 8 * chunk.getNelems());

代码示例来源:origin: Unidata/thredds

while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 2 * chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 4 * chunk.getNelems());
while (index.hasNext()) {
 Layout.Chunk chunk = index.next();
 count += raf.readToByteChannel( out, chunk.getSrcPos(), 8 * chunk.getNelems());

相关文章