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

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

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

RandomAccessFile.readBytes介绍

[英]Read fully count number of bytes
[中]读取完全计数字节数

代码示例

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

  1. /**
  2. * Read up to <code>b.length( )</code> bytes into an array. This
  3. * will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @return the actual number of bytes read, or -1 if there is not
  7. * more data due to the end of the file being reached.
  8. * @throws IOException if an I/O error occurrs.
  9. */
  10. public int read(byte b[]) throws IOException {
  11. return readBytes(b, 0, b.length);
  12. }

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

  1. /**
  2. * Read up to <code>b.length( )</code> bytes into an array. This
  3. * will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @return the actual number of bytes read, or -1 if there is not
  7. * more data due to the end of the file being reached.
  8. * @throws IOException if an I/O error occurrs.
  9. */
  10. public int read(byte b[]) throws IOException {
  11. return readBytes(b, 0, b.length);
  12. }

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

  1. /**
  2. * Read up to <code>b.length( )</code> bytes into an array. This
  3. * will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @return the actual number of bytes read, or -1 if there is not
  7. * more data due to the end of the file being reached.
  8. * @throws IOException if an I/O error occurrs.
  9. */
  10. public int read(byte b[]) throws IOException {
  11. return readBytes(b, 0, b.length);
  12. }

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

  1. /**
  2. * Read up to <code>b.length( )</code> bytes into an array. This
  3. * will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @return the actual number of bytes read, or -1 if there is not
  7. * more data due to the end of the file being reached.
  8. * @throws IOException if an I/O error occurrs.
  9. */
  10. public int read(byte b[]) throws IOException {
  11. return readBytes(b, 0, b.length);
  12. }

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

  1. /**
  2. * Read up to <code>len</code> bytes into an array, at a specified
  3. * offset. This will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @param off the offset in the array where copying will start.
  7. * @param len the number of bytes to copy.
  8. * @return the actual number of bytes read, or -1 if there is not
  9. * more data due to the end of the file being reached.
  10. * @throws IOException if an I/O error occurrs.
  11. */
  12. public int read(byte b[], int off, int len) throws IOException {
  13. return readBytes(b, off, len);
  14. }

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

  1. /**
  2. * Read up to <code>len</code> bytes into an array, at a specified
  3. * offset. This will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @param off the offset in the array where copying will start.
  7. * @param len the number of bytes to copy.
  8. * @return the actual number of bytes read, or -1 if there is not
  9. * more data due to the end of the file being reached.
  10. * @throws IOException if an I/O error occurrs.
  11. */
  12. public int read(byte b[], int off, int len) throws IOException {
  13. return readBytes(b, off, len);
  14. }

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

  1. /**
  2. * Read up to <code>len</code> bytes into an array, at a specified
  3. * offset. This will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @param off the offset in the array where copying will start.
  7. * @param len the number of bytes to copy.
  8. * @return the actual number of bytes read, or -1 if there is not
  9. * more data due to the end of the file being reached.
  10. * @throws IOException if an I/O error occurrs.
  11. */
  12. public int read(byte b[], int off, int len) throws IOException {
  13. return readBytes(b, off, len);
  14. }

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

  1. /**
  2. * Read up to <code>len</code> bytes into an array, at a specified
  3. * offset. This will block until at least one byte has been read.
  4. *
  5. * @param b the byte array to receive the bytes.
  6. * @param off the offset in the array where copying will start.
  7. * @param len the number of bytes to copy.
  8. * @return the actual number of bytes read, or -1 if there is not
  9. * more data due to the end of the file being reached.
  10. * @throws IOException if an I/O error occurrs.
  11. */
  12. public int read(byte b[], int off, int len) throws IOException {
  13. return readBytes(b, off, len);
  14. }

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

  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 = new String(raf.readBytes(10));
  5. while (endRecord.equals("END RECORD")) {
  6. endRecord = 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. 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: Unidata/thredds

  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/netcdf

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

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

  1. List<Record> readData() throws IOException {
  2. List<Record> records = new ArrayList<Record>();
  3. raf.seek(filePos + 40);
  4. byte[] b = raf.readBytes(reportLen - 40);
  5. if (showData) System.out.println("\n" + new String(b));
  6. if (showData) System.out.println(this);
  7. int offset = 0;
  8. while (true) {
  9. Record record = new Record();
  10. offset = record.read(b, offset);
  11. records.add(record);
  12. if (record.next >= reportLen / 10) break;
  13. }
  14. return records;
  15. }

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

  1. List<Record> readData() throws IOException {
  2. List<Record> records = new ArrayList<>();
  3. raf.seek(filePos + 40);
  4. byte[] b = raf.readBytes(reportLen - 40);
  5. if (showData) System.out.println("\n" + new String(b, CDM.utf8Charset));
  6. if (showData) System.out.println(this);
  7. int offset = 0;
  8. while (true) {
  9. Record record = new Record();
  10. offset = record.read(b, offset);
  11. records.add(record);
  12. if (record.next >= reportLen / 10) break;
  13. }
  14. return records;
  15. }

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

  1. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  2. raf.seek(0);
  3. if (raf.length() < 60) return false;
  4. byte[] h = raf.readBytes(60);
  5. // 32 - 56 are X's
  6. for (int i = 32; i < 56; i++)
  7. if (h[i] != (byte) 'X') return false;
  8. try {
  9. short hour = Short.parseShort(new String(h, 0, 2, CDM.utf8Charset));
  10. short minute = Short.parseShort(new String(h, 2, 2, CDM.utf8Charset));
  11. short year = Short.parseShort(new String(h, 4, 2, CDM.utf8Charset));
  12. short month = Short.parseShort(new String(h, 6, 2, CDM.utf8Charset));
  13. short day = Short.parseShort(new String(h, 8, 2, CDM.utf8Charset));
  14. if ((hour < 0) || (hour > 24)) return false;
  15. if ((minute < 0) || (minute > 60)) return false;
  16. if ((year < 0) || (year > 100)) return false;
  17. if ((month < 0) || (month > 12)) return false;
  18. if ((day < 0) || (day > 31)) return false;
  19. } catch (Exception e) {
  20. return false;
  21. }
  22. return true;
  23. }

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

  1. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  2. raf.seek(0);
  3. if (raf.length() < 60) return false;
  4. byte[] h = raf.readBytes(60);
  5. // 32 - 56 are X's
  6. for (int i = 32; i < 56; i++)
  7. if (h[i] != (byte) 'X') return false;
  8. try {
  9. short hour = Short.parseShort(new String(h, 0, 2));
  10. short minute = Short.parseShort(new String(h, 2, 2));
  11. short year = Short.parseShort(new String(h, 4, 2));
  12. short month = Short.parseShort(new String(h, 6, 2));
  13. short day = Short.parseShort(new String(h, 8, 2));
  14. if ((hour < 0) || (hour > 24)) return false;
  15. if ((minute < 0) || (minute > 60)) return false;
  16. if ((year < 0) || (year > 100)) return false;
  17. if ((month < 0) || (month > 12)) return false;
  18. if ((day < 0) || (day > 31)) return false;
  19. } catch (Exception e) {
  20. return false;
  21. }
  22. return true;
  23. }

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

  1. List<Record> readData() throws IOException {
  2. List<Record> records = new ArrayList<>();
  3. raf.seek(filePos + 40);
  4. byte[] b = raf.readBytes(reportLen - 40);
  5. if (showData) System.out.println("\n" + new String(b, CDM.utf8Charset));
  6. if (showData) System.out.println(this);
  7. int offset = 0;
  8. while (true) {
  9. Record record = new Record();
  10. offset = record.read(b, offset);
  11. records.add(record);
  12. if (record.next >= reportLen / 10) break;
  13. }
  14. return records;
  15. }

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

  1. public boolean isValidFile(RandomAccessFile raf) throws IOException {
  2. raf.seek(0);
  3. if (raf.length() < 60) return false;
  4. byte[] h = raf.readBytes(60);
  5. // 32 - 56 are X's
  6. for (int i = 32; i < 56; i++)
  7. if (h[i] != (byte) 'X') return false;
  8. try {
  9. short hour = Short.parseShort(new String(h, 0, 2, CDM.utf8Charset));
  10. short minute = Short.parseShort(new String(h, 2, 2, CDM.utf8Charset));
  11. short year = Short.parseShort(new String(h, 4, 2, CDM.utf8Charset));
  12. short month = Short.parseShort(new String(h, 6, 2, CDM.utf8Charset));
  13. short day = Short.parseShort(new String(h, 8, 2, CDM.utf8Charset));
  14. if ((hour < 0) || (hour > 24)) return false;
  15. if ((minute < 0) || (minute > 60)) return false;
  16. if ((year < 0) || (year > 100)) return false;
  17. if ((month < 0) || (month > 12)) return false;
  18. if ((day < 0) || (day > 31)) return false;
  19. } catch (Exception e) {
  20. return false;
  21. }
  22. return true;
  23. }

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

  1. private void readHeader(RandomAccessFile raf) throws IOException {
  2. byte[] h = raf.readBytes(60);
  3. // 12 00 070101
  4. short hour = Short.parseShort( new String(h, 0, 2, CDM.utf8Charset));
  5. short minute = Short.parseShort(new String(h, 2, 2, CDM.utf8Charset));
  6. short year = Short.parseShort(new String(h, 4, 2, CDM.utf8Charset));
  7. short month = Short.parseShort(new String(h, 6, 2, CDM.utf8Charset));
  8. short day = Short.parseShort(new String(h, 8, 2, CDM.utf8Charset));
  9. int fullyear = (year > 30) ? 1900 + year : 2000 + year;
  10. if (cal == null) {
  11. cal = Calendar.getInstance();
  12. cal.setTimeZone(TimeZone.getTimeZone("UTC"));
  13. }
  14. cal.clear();
  15. cal.set(fullyear, month - 1, day, hour, minute);
  16. refDate = cal.getTime();
  17. if (showHeader) System.out.println("\nhead=" + new String(h, CDM.utf8Charset) +
  18. " date= " + dateFormatter.toDateTimeString(refDate));
  19. int b, count = 0;
  20. while ((b = raf.read()) == (int) 'X') count++;
  21. char c = (char) b;
  22. if (showSkip) System.out.println(" b=" + b + " c=" + c + " at " + raf.getFilePointer() + " skipped= " + count);
  23. raf.skipBytes(-1); // go back one
  24. }

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

  1. private boolean endFile(RandomAccessFile raf) throws IOException {
  2. if (showSkip) System.out.println(" endFile start at " + raf.getFilePointer());
  3. String endRecord = new String(raf.readBytes(10));
  4. while (endRecord.equals("ENDOF FILE")) {
  5. endRecord = 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. }

相关文章