ucar.unidata.io.RandomAccessFile类的使用及代码示例

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

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

RandomAccessFile介绍

[英]A buffered drop-in replacement for java.io.RandomAccessFile. Instances of this class realise substantial speed increases over java.io.RandomAccessFile through the use of buffering. This is a subclass of Object, as it was not possible to subclass java.io.RandomAccessFile because many of the methods are final. However, if it is necessary to use RandomAccessFile and java.io.RandomAccessFile interchangeably, both classes implement the DataInput and DataOutput interfaces.

By Russ Rew, based on BufferedRandomAccessFile by Alex McManus, based on Sun's source code for java.io.RandomAccessFile. For Alex McManus version from which this derives, see his Freeware Java Classes.

Must be thread confined - that is, can only be used by a single thread at a time..
[中]一个缓冲的java替代品。伊奥。随机存取文件。与java相比,这个类的实例实现了显著的速度提升。伊奥。通过使用缓冲来随机访问文件。这是Object的子类,因为不可能将java子类化。伊奥。RandomAccessFile,因为许多方法都是最终的。但是,如果有必要使用RandomAccessFile和java。伊奥。RandomAccessFile这两个类可以互换地实现DataInput和DataOutput接口。
由Russ Rew编写,基于Alex McManus编写的BufferedRandomAccess文件,基于Sun的java源代码。伊奥。随机存取文件。对于Alex McManus版本,请参见他的Freeware Java Classes
必须是线程限制的,也就是说,一次只能由一个线程使用。。

代码示例

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

public void close() throws java.io.IOException {
 if (stnRaf != null) stnRaf.close();
 if (dataRaf != null) dataRaf.close();
 stnRaf = null;
 dataRaf = null;
}

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

/**
 * public by accident, do not use
 *
 * @param indexRaf the open raf of the index file
 */
void setIndexRaf(RandomAccessFile indexRaf) {
 this.indexRaf = indexRaf;
 if (indexRaf != null) {
  this.indexFilename = indexRaf.getLocation();
 }
}

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

SeqIter(StructureDataRegexp.Vinfo vinfo) throws IOException {
 this.vinfo = vinfo;
 totalBytes = (int) vinfo.rafile.length();
 vinfo.rafile.seek(0);
}

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

Record9() throws IOException {
  raf.read(heapId);
  flags = raf.readByte();
  creationOrder = raf.readInt();
 }
}

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

static public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) throws IOException {
 // this is the first time we try to read the file - if there's a problem we get a IOException
 raf.seek(0);
 byte[] b = new byte[4];
 raf.read(b);
 for (int i = 0; i < 3; i++)
  if (b[i] != MAGIC[i])
   return false;
 return ((b[3] == 1) || (b[3] == 2));
}

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

void read() throws IOException {
 raf.seek(offset);
 xdim = raf.readInt();
 ydim = raf.readInt();
 raf.skipBytes(2);
 nt_ref = raf.readShort();
 nelems = raf.readShort();
 interlace = raf.readShort();
 compress = raf.readShort();
 compress_ref = raf.readShort();
}

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

private void readHeader() throws IOException {
 raf.seek(32);
 raf.order(ByteOrder.LITTLE_ENDIAN);
 int itype = raf.readInt();
 type = assignType(itype);
 bb = readBoundingBox();
}

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

void dump(String head, long filePos, int nbytes, boolean count) throws IOException {
 long savePos = raf.getFilePointer();
 if (filePos >= 0) raf.seek(filePos);
 byte[] mess = new byte[nbytes];
 raf.read(mess);
 printBytes(head, mess, nbytes, false, debugOut);
 raf.seek(savePos);
}

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

public static void main(String[] args) throws IOException {
 int count = 0;
 RandomAccessFile raf = new RandomAccessFile("Q:/cdmUnitTest/formats/grib2/LMPEF_CLM_050518_1200.grb", "r");
 System.out.printf("Read %s%n", raf.getLocation());
 Grib2RecordScanner scan = new Grib2RecordScanner(raf);
 while (scan.hasNext()) {
  scan.next();
  count++;
 }
 raf.close();
 System.out.printf("count=%d%n",count);
}

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

public Grib2RecordScanner(RandomAccessFile raf) throws IOException {
 this.raf = raf;
 raf.seek(0);
 raf.order(RandomAccessFile.BIG_ENDIAN);
 lastPos = 0;
 if (debugRepeat) System.out.printf(" Grib2RecordScanner %s%n", raf.getLocation());
}

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

public byte[] getData(int offset) throws IOException {
  int    readLen = (int) raf.length();
  byte[] b       = new byte[readLen];
  int    pos     = 0;
  raf.seek(pos);
  raf.readFully(b);
  return b;
}

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

private static void dump(String filename) throws IOException {
 System.out.printf("Dump %s%n", filename);
 RandomAccessFile raf = new RandomAccessFile(filename, "r");
 NetcdfFile ncfile = new MyNetcdfFile();
 // its a netcdf-3 file
 raf.order(RandomAccessFile.BIG_ENDIAN);
 N3header headerParser = new N3header();
 headerParser.read(raf, ncfile, new Formatter(System.out));
 raf.close();
}

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

public FileCacheable open(DatasetUrl durl, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException {
  String location = StringUtil2.replace(durl.trueurl, "\\", "/"); // canonicalize the name
  RandomAccessFile result = new RandomAccessFile(location, "r", buffer_size);
  result.cacheState = 1;  // in use
  return result;
 }
};

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

static public boolean isValidFile(RandomAccessFile raf) throws IOException {
 raf.seek(0);
 if (!raf.searchForward(matcher, 8000)) return false; // must find "GRIB" in first 8k
 raf.skipBytes(4);
 //  Read Section 0 Indicator Section to get Edition number
 Grib2IndicatorSection is = new Grib2IndicatorSection(raf);  // section 0
 if (is.getGribEdition() != 1 && is.getGribEdition() != 2)
  return false;
 if (is.getGribLength() > raf.length())
  return false;
 return true;
}

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

private void skip(int nbytes) throws IOException {
 int pad = padding(nbytes);
 if (pad > 0)
  raf.seek(raf.getFilePointer() + pad);
}

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

void dump(String head, long filePos, int nbytes, boolean count) throws IOException {
 long savePos = raf.getFilePointer();
 if (filePos >= 0) raf.seek(filePos);
 byte[] mess = new byte[nbytes];
 raf.readFully(mess);
 printBytes(head, mess, nbytes, false, debugOut);
 raf.seek(savePos);
}

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

void read() throws IOException {
 raf.seek(offset);
 byte[] buff = new byte[length];
 raf.readFully(buff);
 bb = ByteBuffer.wrap(buff);
}

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

Record70() throws IOException {
  location = raf.readByte();
  refCount = raf.readInt();
  raf.readFully(id);
 }
}

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

/**
 * Check if this is a valid SIGMET-IRIS file for this IOServiceProvider.
 */
public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) {
 try {
  raf.order(RandomAccessFile.LITTLE_ENDIAN);
  raf.seek(24);
  return (raf.readShort() == (short) 15);
 } catch (IOException ioe) {
  System.out.println("In isValidFile(): " + ioe.toString());
  return false;
 }
}

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

public static void main(String[] args) throws IOException {
  int count = 0;
  RandomAccessFile raf = new RandomAccessFile("Q:/cdmUnitTest/formats/grib1/ECMWF.hybrid.grib1", "r");
  Grib1RecordScanner scan = new Grib1RecordScanner(raf);
  while (scan.hasNext()) {
   scan.next();
   count++;
  }
  raf.close();
  System.out.printf("count=%d%n",count);
 }
}

相关文章