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

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

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

RandomAccessFile.seek介绍

[英]Set the position in the file for the next read or write.
[中]在文件中设置下一次读取或写入的位置。

代码示例

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

  1. /**
  2. * Constructor
  3. *
  4. * @param raf the RandomAccessFile
  5. * @param startPos points to start of data in data section, in bytes
  6. * @throws IOException on read error
  7. */
  8. public BitReader(RandomAccessFile raf, long startPos) throws IOException {
  9. this.raf = raf;
  10. this.startPos = startPos;
  11. raf.seek(startPos);
  12. }

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

  1. @Override
  2. public StructureDataIterator reset() {
  3. bytesRead = 0;
  4. recno = 0;
  5. try {
  6. vinfo.raf.seek(0);
  7. } catch (IOException e) {
  8. throw new RuntimeException(e);
  9. }
  10. return this;
  11. }

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

  1. @Override
  2. public StructureDataIterator reset() {
  3. recno = 0;
  4. try {
  5. vinfo.rafile.seek(0);
  6. } catch (IOException e) {
  7. throw new RuntimeException(e);
  8. }
  9. return this;
  10. }

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

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

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

  1. public boolean isValidFile( RandomAccessFile raf) throws IOException {
  2. try {
  3. raf.seek(0);
  4. String test = raf.readString(8);
  5. return test.equals( Level2VolumeScan.ARCHIVE2) || test.equals( Level2VolumeScan.AR2V0001) ||
  6. test.equals( Level2VolumeScan.AR2V0003)|| test.equals( Level2VolumeScan.AR2V0004) ||
  7. test.equals( Level2VolumeScan.AR2V0002) || test.equals( Level2VolumeScan.AR2V0006) ||
  8. test.equals( Level2VolumeScan.AR2V0007);
  9. } catch (IOException ioe) {
  10. return false;
  11. }
  12. }

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

  1. void show(RandomAccessFile raf) throws IOException {
  2. raf.seek(filePos);
  3. byte[] b = raf.readBytes(40);
  4. System.out.println(new String(b, CDM.utf8Charset));
  5. }

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

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

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

  1. public final byte[] getOptiondsalSection(RandomAccessFile raf) throws
  2. IOException {
  3. if (!hasOptionalSection) return null;
  4. byte[] optionalSection = new byte[optionalSectionLen - 4];
  5. raf.seek(optionalSectionPos);
  6. int nRead = raf.read(optionalSection);
  7. if (nRead != optionalSection.length)
  8. log.warn("Error reading optional section -- expected " +
  9. optionalSection.length + " but read " + nRead);
  10. return optionalSection;
  11. }

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

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

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

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

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

  1. void read() throws IOException {
  2. raf.seek(offset);
  3. nelems = length / 4;
  4. elem_tag = new short[nelems];
  5. elem_ref = new short[nelems];
  6. for (int i = 0; i < nelems; i++) {
  7. elem_tag[i] = raf.readShort();
  8. elem_ref[i] = raf.readShort();
  9. }
  10. }

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

  1. static boolean validatePIB(ucar.unidata.io.RandomAccessFile raf) throws IOException {
  2. int pos = 0;
  3. raf.seek(pos);
  4. // gini header process
  5. String pib = raf.readString(GINI_PIB_LEN + GINI_HED_LEN);
  6. return findWMOHeader(pib) != 0;
  7. }

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

  1. public Grib1SectionBitMap(RandomAccessFile raf) throws IOException {
  2. startingPosition = raf.getFilePointer();
  3. // octets 1-3 (Length of section)
  4. int length = GribNumbers.int3(raf);
  5. raf.seek(startingPosition + length);
  6. }

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

  1. HeapIdentifier(long address) throws IOException {
  2. // header information is in le byte order
  3. raf.order(RandomAccessFile.LITTLE_ENDIAN);
  4. raf.seek(address);
  5. nelems = raf.readInt();
  6. heapAddress = readOffset();
  7. index = raf.readInt();
  8. if (debugDetail)
  9. debugOut.println(" read HeapIdentifier address=" + address + this);
  10. if (debugHeap) dump("heapIdentifier", getFileOffset(address), 16, true);
  11. }

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

  1. Object readDoubleArray1D(int offsetInRecord) throws IOException {
  2. int elementSizeInBytes = 8;
  3. double[] array = new double[header.getNumDataRecords()];
  4. this.raf.seek(header.getRecordSizeInBytes() * header.getNumHeaderRecords() + offsetInRecord);
  5. for (int i = 0; i < header.getNumDataRecords(); i++) {
  6. this.raf.readDouble(array, i, 1);
  7. this.raf.skipBytes(header.getRecordSizeInBytes() - elementSizeInBytes);
  8. }
  9. return (array);
  10. }

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

  1. Object readFloatArray1D(int offsetInRecord) throws IOException {
  2. int elementSizeInBytes = 4;
  3. float[] array = new float[header.getNumDataRecords()];
  4. this.raf.seek(header.getRecordSizeInBytes() * header.getNumHeaderRecords() + offsetInRecord);
  5. for (int i = 0; i < header.getNumDataRecords(); i++) {
  6. this.raf.readFloat(array, i, 1);
  7. this.raf.skipBytes(header.getRecordSizeInBytes() - elementSizeInBytes);
  8. }
  9. return (array);
  10. }

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

  1. Object readFloatArray1D(int offsetInRecord) throws IOException {
  2. int elementSizeInBytes = 4;
  3. float[] array = new float[header.getNumDataRecords()];
  4. this.raf.seek(header.getRecordSizeInBytes() * header.getNumHeaderRecords() + offsetInRecord);
  5. for (int i = 0; i < header.getNumDataRecords(); i++) {
  6. this.raf.readFloat(array, i, 1);
  7. this.raf.skipBytes(header.getRecordSizeInBytes() - elementSizeInBytes);
  8. }
  9. return (array);
  10. }

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

  1. void read() throws IOException {
  2. raf.seek(offset);
  3. xdim = raf.readInt();
  4. ydim = raf.readInt();
  5. raf.skipBytes(2);
  6. nt_ref = raf.readShort();
  7. nelems = raf.readShort();
  8. interlace = raf.readShort();
  9. compress = raf.readShort();
  10. compress_ref = raf.readShort();
  11. }

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

  1. void read() throws IOException {
  2. raf.seek(offset);
  3. xdim = raf.readInt();
  4. ydim = raf.readInt();
  5. raf.skipBytes(2);
  6. nt_ref = raf.readShort();
  7. nelems = raf.readShort();
  8. interlace = raf.readShort();
  9. compress = raf.readShort();
  10. compress_ref = raf.readShort();
  11. }

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

  1. protected void read() throws IOException {
  2. raf.seek(offset);
  3. xdim = raf.readInt();
  4. ydim = raf.readInt();
  5. raf.skipBytes(2);
  6. nt_ref = raf.readShort();
  7. nelems = raf.readShort();
  8. interlace = raf.readShort();
  9. compress = raf.readShort();
  10. compress_ref = raf.readShort();
  11. }

相关文章