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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

private boolean endRecord(RandomAccessFile raf) throws IOException {
 if (showSkip) System.out.print(" endRecord start at " + raf.getFilePointer());
 int skipped = 0;
 String endRecord = new String(raf.readBytes(10));
 while (endRecord.equals("END RECORD")) {
  endRecord = new String(raf.readBytes(10));
  skipped++;
 }
 if (showSkip) System.out.println(" last 10 chars= " + endRecord + " skipped= " + skipped);
 return true;
}

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

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

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

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

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

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

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

List<Record> readData() throws IOException {
 List<Record> records = new ArrayList<Record>();
 raf.seek(filePos + 40);
 byte[] b = raf.readBytes(reportLen - 40);
 if (showData) System.out.println("\n" + new String(b));
 if (showData) System.out.println(this);
 int offset = 0;
 while (true) {
  Record record = new Record();
  offset = record.read(b, offset);
  records.add(record);
  if (record.next >= reportLen / 10) break;
 }
 return records;
}

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

List<Record> readData() throws IOException {
 List<Record> records = new ArrayList<>();
 raf.seek(filePos + 40);
 byte[] b = raf.readBytes(reportLen - 40);
 if (showData) System.out.println("\n" + new String(b, CDM.utf8Charset));
 if (showData) System.out.println(this);
 int offset = 0;
 while (true) {
  Record record = new Record();
  offset = record.read(b, offset);
  records.add(record);
  if (record.next >= reportLen / 10) break;
 }
 return records;
}

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

public boolean isValidFile(RandomAccessFile raf) throws IOException {
 raf.seek(0);
 if (raf.length() < 60) return false;
 byte[] h = raf.readBytes(60);
 // 32 - 56 are X's
 for (int i = 32; i < 56; i++)
  if (h[i] != (byte) 'X') return false;
 try {
  short hour = Short.parseShort(new String(h, 0, 2, CDM.utf8Charset));
  short minute = Short.parseShort(new String(h, 2, 2, CDM.utf8Charset));
  short year = Short.parseShort(new String(h, 4, 2, CDM.utf8Charset));
  short month = Short.parseShort(new String(h, 6, 2, CDM.utf8Charset));
  short day = Short.parseShort(new String(h, 8, 2, CDM.utf8Charset));
  if ((hour < 0) || (hour > 24)) return false;
  if ((minute < 0) || (minute > 60)) return false;
  if ((year < 0) || (year > 100)) return false;
  if ((month < 0) || (month > 12)) return false;
  if ((day < 0) || (day > 31)) return false;
 } catch (Exception e) {
  return false;
 }
 return true;
}

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

public boolean isValidFile(RandomAccessFile raf) throws IOException {
 raf.seek(0);
 if (raf.length() < 60) return false;
 byte[] h = raf.readBytes(60);
 // 32 - 56 are X's
 for (int i = 32; i < 56; i++)
  if (h[i] != (byte) 'X') return false;
 try {
  short hour = Short.parseShort(new String(h, 0, 2));
  short minute = Short.parseShort(new String(h, 2, 2));
  short year = Short.parseShort(new String(h, 4, 2));
  short month = Short.parseShort(new String(h, 6, 2));
  short day = Short.parseShort(new String(h, 8, 2));
  if ((hour < 0) || (hour > 24)) return false;
  if ((minute < 0) || (minute > 60)) return false;
  if ((year < 0) || (year > 100)) return false;
  if ((month < 0) || (month > 12)) return false;
  if ((day < 0) || (day > 31)) return false;
 } catch (Exception e) {
  return false;
 }
 return true;
}

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

List<Record> readData() throws IOException {
 List<Record> records = new ArrayList<>();
 raf.seek(filePos + 40);
 byte[] b = raf.readBytes(reportLen - 40);
 if (showData) System.out.println("\n" + new String(b, CDM.utf8Charset));
 if (showData) System.out.println(this);
 int offset = 0;
 while (true) {
  Record record = new Record();
  offset = record.read(b, offset);
  records.add(record);
  if (record.next >= reportLen / 10) break;
 }
 return records;
}

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

public boolean isValidFile(RandomAccessFile raf) throws IOException {
 raf.seek(0);
 if (raf.length() < 60) return false;
 byte[] h = raf.readBytes(60);
 // 32 - 56 are X's
 for (int i = 32; i < 56; i++)
  if (h[i] != (byte) 'X') return false;
 try {
  short hour = Short.parseShort(new String(h, 0, 2, CDM.utf8Charset));
  short minute = Short.parseShort(new String(h, 2, 2, CDM.utf8Charset));
  short year = Short.parseShort(new String(h, 4, 2, CDM.utf8Charset));
  short month = Short.parseShort(new String(h, 6, 2, CDM.utf8Charset));
  short day = Short.parseShort(new String(h, 8, 2, CDM.utf8Charset));
  if ((hour < 0) || (hour > 24)) return false;
  if ((minute < 0) || (minute > 60)) return false;
  if ((year < 0) || (year > 100)) return false;
  if ((month < 0) || (month > 12)) return false;
  if ((day < 0) || (day > 31)) return false;
 } catch (Exception e) {
  return false;
 }
 return true;
}

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

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

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

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

相关文章