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

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

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

RandomAccessFile.read介绍

[英]Read a byte of data from the file, blocking until data is available.
[中]从文件中读取一个字节的数据,直到数据可用为止。

代码示例

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

  1. Record9() throws IOException {
  2. raf.read(heapId);
  3. flags = raf.readByte();
  4. creationOrder = raf.readInt();
  5. }
  6. }

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

  1. private long readVariableSizeN(int nbytes) throws IOException {
  2. int[] ch = new int[nbytes];
  3. for (int i = 0; i < nbytes; i++)
  4. ch[i] = raf.read();
  5. long result = ch[nbytes - 1];
  6. for (int i = nbytes - 2; i >= 0; i--) {
  7. result = result << 8;
  8. result += ch[i];
  9. }
  10. return result;
  11. }

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

  1. Record5() throws IOException {
  2. nameHash = raf.readInt();
  3. raf.read(heapId);
  4. if (debugBtree2)
  5. debugOut.println(" record5 nameHash=" + nameHash + " heapId=" + Misc.showBytes(heapId));
  6. }
  7. }

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

  1. Record6() throws IOException {
  2. creationOrder = raf.readLong();
  3. raf.read(heapId);
  4. if (debugBtree2)
  5. debugOut.println(" record6 creationOrder=" + creationOrder + " heapId=" + Misc.showBytes(heapId));
  6. }
  7. }

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

  1. Type40(RandomAccessFile raf) throws IOException {
  2. super(raf);
  3. this.compressionMethod = raf.read();
  4. this.compressionRatio = raf.read();
  5. }

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

  1. private int readVInt(RandomAccessFile raf) throws IOException {
  2. byte b = (byte) raf.read();
  3. int i = b & 0x7F;
  4. for (int shift = 7; (b & 0x80) != 0; shift += 7) {
  5. b = (byte) raf.read();
  6. i |= (b & 0x7F) << shift;
  7. }
  8. return i;
  9. }

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

  1. private long readVariableSizeN(int nbytes) throws IOException {
  2. int[] ch = new int[nbytes];
  3. for (int i = 0; i < nbytes; i++)
  4. ch[i] = raf.read();
  5. long result = ch[nbytes - 1];
  6. for (int i = nbytes - 2; i >= 0; i--) {
  7. result = result << 8;
  8. result += ch[i];
  9. }
  10. return result;
  11. }

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

  1. /**
  2. * Read a String of known length.
  3. *
  4. * @param size number of bytes
  5. * @return String result
  6. * @throws java.io.IOException on io error
  7. */
  8. private String readStringFixedLength(int size) throws IOException {
  9. byte[] s = new byte[size];
  10. raf.read(s);
  11. return new String(s, CDM.utf8Charset); // all Strings are UTF-8 unicode
  12. }

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

  1. /**
  2. * Convert 2 bytes into a signed integer.
  3. *
  4. * @param raf
  5. * @return integer value
  6. * @throws IOException
  7. */
  8. public static int int2(RandomAccessFile raf) throws IOException {
  9. int a = raf.read();
  10. int b = raf.read();
  11. return int2(a, b);
  12. }

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

  1. /**
  2. * Convert 2 bytes into an unsigned integer.
  3. *
  4. * @param raf
  5. * @return integer value
  6. * @throws IOException
  7. */
  8. public static int uint2(RandomAccessFile raf) throws IOException {
  9. int a = raf.read();
  10. int b = raf.read();
  11. return uint2(a, b);
  12. }

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

  1. /**
  2. * Convert 2 bytes into an unsigned integer.
  3. *
  4. * @param raf read from here
  5. * @return integer value
  6. * @throws IOException on read error
  7. */
  8. public static int uint2(RandomAccessFile raf) throws IOException {
  9. int a = raf.read();
  10. int b = raf.read();
  11. return uint2(a, b);
  12. }

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

  1. private String readString(int len) throws IOException {
  2. if (len < 0)
  3. System.out.println("what");
  4. byte[] b = new byte[len];
  5. raf.read(b);
  6. int count;
  7. for (count = 0; count < len; count++)
  8. if (b[count] == 0)
  9. break;
  10. return new String(b, 0, count, CDM.utf8Charset);
  11. }

代码示例来源: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: 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/bufr

  1. public final byte[] getOptionalSection(RandomAccessFile raf) throws IOException {
  2. if (!hasOptionalSection) return null;
  3. byte[] optionalSection = new byte[optionalSectionLen - 4];
  4. raf.seek(optionalSectionPos);
  5. raf.read(optionalSection);
  6. return optionalSection;
  7. }

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

  1. private boolean readAndTest(RandomAccessFile raf, byte[] test) throws IOException {
  2. byte[] b = new byte[test.length];
  3. raf.read(b);
  4. return test(b, test);
  5. }

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

  1. public Grib2SectionBitMap(RandomAccessFile raf) throws IOException {
  2. startingPosition = raf.getFilePointer();
  3. // octets 1-4 (Length of section)
  4. int length = GribNumbers.int4(raf);
  5. // octet 5
  6. int section = raf.read();
  7. if (section != 6)
  8. throw new IllegalArgumentException("Not a GRIB-2 Bitmap section");
  9. // octet 6
  10. bitMapIndicator = raf.read();
  11. raf.seek(startingPosition + length);
  12. }

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

  1. /**
  2. * Constructs a <tt>BufrIndicatorSection</tt> object from a raf.
  3. *
  4. * @param raf RandomAccessFile with IndicatorSection content
  5. * @throws IOException on read error
  6. */
  7. public BufrIndicatorSection(RandomAccessFile raf) throws IOException {
  8. this.startPos = raf.getFilePointer() - 4; // start of BUFR message, including "BUFR"
  9. bufrLength = BufrNumbers.uint3(raf);
  10. edition = raf.read();
  11. }

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

  1. public Grib2SectionData(RandomAccessFile raf) throws IOException {
  2. startingPosition = raf.getFilePointer();
  3. // octets 1-4 (Length of section)
  4. msgLength = GribNumbers.int4(raf);
  5. // octet 5
  6. int section = raf.read();
  7. if (section != 7)
  8. throw new IllegalStateException("Not a Grib2SectionData (section 7)");
  9. // skip to end of the data section
  10. raf.seek(startingPosition + msgLength);
  11. }

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

  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.read(mess);
  6. printBytes(head, mess, nbytes, false, debugOut);
  7. raf.seek(savePos);
  8. }

相关文章