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

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

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

RandomAccessFile.readString介绍

[英]Read a String of known length.
[中]读一个已知长度的字符串。

代码示例

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

  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. return raf.readString(size);
  10. }

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

  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. return raf.readString(size);
  10. }

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

  1. void read() throws IOException {
  2. datemod = raf.readString(14);
  3. if (debug1) {
  4. log.debug(" MessageLastModifiedOld={}", datemod);
  5. }
  6. }

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

  1. void read() throws IOException {
  2. datemod = raf.readString(14);
  3. if (debug1) debugOut.println(" MessageLastModifiedOld=" + datemod);
  4. }

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

  1. private boolean endRecord(RandomAccessFile raf) throws IOException {
  2. if (showSkip) System.out.print(" endRecord start at " + raf.getFilePointer());
  3. int skipped = 0;
  4. String endRecord = raf.readString(10); // new String(raf.readBytes(10), CDM.utf8Charset);
  5. while (endRecord.equals("END RECORD")) {
  6. endRecord = raf.readString(10); // new String(raf.readBytes(10));
  7. skipped++;
  8. }
  9. if (showSkip) System.out.println(" last 10 chars= " + endRecord + " skipped= " + skipped);
  10. return true;
  11. }

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

  1. private boolean endRecord(RandomAccessFile raf) throws IOException {
  2. if (showSkip) System.out.print(" endRecord start at " + raf.getFilePointer());
  3. int skipped = 0;
  4. String endRecord = raf.readString(10); // new String(raf.readBytes(10), CDM.utf8Charset);
  5. while (endRecord.equals("END RECORD")) {
  6. endRecord = raf.readString(10); // new String(raf.readBytes(10));
  7. skipped++;
  8. }
  9. if (showSkip) System.out.println(" last 10 chars= " + endRecord + " skipped= " + skipped);
  10. return true;
  11. }

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

  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: Unidata/thredds

  1. /**
  2. * Check if this is a valid file for this IOServiceProvider.
  3. * You must make this method thread safe, ie dont keep any state.
  4. *
  5. * @param raf RandomAccessFile
  6. * @return true if valid.
  7. * @throws IOException if read error
  8. */
  9. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  10. raf.seek(0);
  11. String test = raf.readString(MAGIC.length());
  12. return test.equals(MAGIC);
  13. }

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

  1. /**
  2. * Check if this is a valid file for this IOServiceProvider.
  3. * You must make this method thread safe, ie dont keep any state.
  4. *
  5. * @param raf RandomAccessFile
  6. * @return true if valid.
  7. * @throws IOException if read error
  8. */
  9. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  10. raf.seek(0);
  11. String test = raf.readString(MAGIC.length());
  12. return test.equals(MAGIC);
  13. }

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

  1. /**
  2. * Check if this is a valid file for this IOServiceProvider.
  3. *
  4. * @param raf RandomAccessFile
  5. * @return true if valid.
  6. * @throws IOException if read error
  7. */
  8. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  9. raf.seek(0);
  10. int n = MAGIC.length();
  11. if (raf.length() < n) {
  12. return false;
  13. }
  14. String got = raf.readString(n);
  15. return (pMAGIC.matcher(got).find() || pMAGIC_OLD.matcher(got).find());
  16. }

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

  1. static public boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) throws IOException {
  2. long filePos = 0;
  3. long size = raf.length();
  4. // search forward for the header
  5. while ((filePos < size) && (filePos < maxHeaderPos)) {
  6. raf.seek(filePos);
  7. String magic = raf.readString(8);
  8. if (magic.equals(hdf5magic))
  9. return true;
  10. filePos = (filePos == 0) ? 512 : 2 * filePos;
  11. }
  12. return false;
  13. }

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

  1. static boolean isValidFile(ucar.unidata.io.RandomAccessFile raf) throws IOException {
  2. long pos = 0;
  3. long size = raf.length();
  4. // search forward for the header
  5. while ((pos < size) && (pos < maxHeaderPos)) {
  6. raf.seek(pos);
  7. String magic = raf.readString(4);
  8. if (magic.equals(shead))
  9. return true;
  10. pos = (pos == 0) ? 512 : 2 * pos;
  11. }
  12. return false;
  13. }

代码示例来源: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: edu.ucar/netcdf

  1. private String getDataBlockStringValue(RandomAccessFile raf, short offset, int skip, int size) throws IOException {
  2. long off = offset + message_offset + MESSAGE_HEADER_SIZE;
  3. raf.seek(off);
  4. raf.skipBytes(skip);
  5. return raf.readString(size);
  6. }

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

  1. private String getDataBlockStringValue(RandomAccessFile raf, short offset, int skip, int size) throws IOException {
  2. long off = offset + message_offset + MESSAGE_HEADER_SIZE;
  3. raf.seek(off);
  4. raf.skipBytes(skip);
  5. return raf.readString(size);
  6. }

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

  1. private String getDataBlockStringValue(RandomAccessFile raf, short offset, int skip, int size) throws IOException {
  2. long off = offset + message_offset + MESSAGE_HEADER_SIZE;
  3. raf.seek(off);
  4. raf.skipBytes(skip);
  5. return raf.readString(size);
  6. }

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

  1. /**
  2. * Check if this is a valid file for this IOServiceProvider.
  3. *
  4. * @param raf RandomAccessFile
  5. * @return true if valid.
  6. */
  7. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  8. try {
  9. raf.order(RandomAccessFile.BIG_ENDIAN);
  10. raf.seek(0);
  11. raf.skipBytes(4);
  12. String test = raf.readString(40);
  13. return test.equals(EMISSIONS) || test.equals(AVERAGE) || test.equals(AIRQUALITY) || test.equals(INSTANT);
  14. } catch (IOException ioe) {
  15. return false;
  16. }
  17. }

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

  1. private boolean endFile(RandomAccessFile raf) throws IOException {
  2. if (showSkip) System.out.println(" endFile start at " + raf.getFilePointer());
  3. String endRecord = raf.readString(10); // new String(raf.readBytes(10));
  4. while (endRecord.equals("ENDOF FILE")) {
  5. endRecord = raf.readString(10); // new String(raf.readBytes(10));
  6. }
  7. try {
  8. while (raf.read() != (int) 'X') ; //find where X's start
  9. while (raf.read() == (int) 'X') ; //skip X's till you run out
  10. raf.skipBytes(-1); // go back one
  11. readHeader(raf);
  12. return true;
  13. } catch (EOFException e) {
  14. return false;
  15. }
  16. }

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

  1. /**
  2. * Read a zero terminated String. Leave file positioned after zero terminator byte.
  3. *
  4. * @param raf from this file
  5. * @return String (dont include zero terminator)
  6. * @throws java.io.IOException on io error
  7. */
  8. private String readString(RandomAccessFile raf) throws IOException {
  9. long filePos = raf.getFilePointer();
  10. int count = 0;
  11. while (raf.readByte() != 0) count++;
  12. raf.seek(filePos);
  13. String result = raf.readString(count);
  14. raf.readByte(); // skip the zero byte! nn
  15. return result;
  16. }

相关文章