Java Code Examples for ucar.unidata.io.RandomAccessFile#readByte()

The following examples show how to use ucar.unidata.io.RandomAccessFile#readByte() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: H5objects.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Read a zero terminated String at current position; advance file to a multiple of 8.
 *
 * @param raf from this file
 * @return String (dont include zero terminator)
 * @throws IOException on io error
 */
private String readString8(RandomAccessFile raf) throws IOException {
  long filePos = raf.getFilePointer();

  int count = 0;
  while (raf.readByte() != 0)
    count++;

  raf.seek(filePos);
  byte[] s = new byte[count];
  raf.readFully(s);

  // skip to 8 byte boundary, note zero byte is skipped
  count++;
  count += padding(count, 8);
  raf.seek(filePos + count);

  return new String(s, StandardCharsets.UTF_8); // all Strings are UTF-8 unicode
}
 
Example 2
Source File: H5header.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Read a zero terminated String at current position; advance file to a multiple of 8.
 *
 * @param raf from this file
 * @return String (dont include zero terminator)
 * @throws java.io.IOException on io error
 */
private String readString8(RandomAccessFile raf) throws IOException {
  long filePos = raf.getFilePointer();

  int count = 0;
  while (raf.readByte() != 0)
    count++;

  raf.seek(filePos);
  byte[] s = new byte[count];
  raf.readFully(s);

  // skip to 8 byte boundary, note zero byte is skipped
  count++;
  count += padding(count, 8);
  raf.seek(filePos + count);

  return new String(s, StandardCharsets.UTF_8); // all Strings are UTF-8 unicode
}
 
Example 3
Source File: Cinrad2Record.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
SweepInfo(RandomAccessFile din, int hoff) throws IOException {
  din.seek(hoff);
  amb = din.readByte();
  arotate = (short) din.readUnsignedShort();
  pref1 = (short) din.readUnsignedShort();
  pref2 = (short) din.readUnsignedShort();
  spulseW = (short) din.readUnsignedShort();
  maxV = (short) din.readUnsignedShort();
  maxL = (short) din.readUnsignedShort();
  binWidth = (short) din.readUnsignedShort();
  binnumber = (short) din.readUnsignedShort();
  recordnumber = (short) din.readUnsignedShort();
  elevationAngle = (short) din.readUnsignedShort() / 100.0f;
}
 
Example 4
Source File: H5objects.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Read a zero terminated String. Leave file positioned after zero terminator byte.
 *
 * @param raf from this file
 * @return String (dont include zero terminator)
 * @throws IOException on io error
 */
private String readString(RandomAccessFile raf) throws IOException {
  long filePos = raf.getFilePointer();

  int count = 0;
  while (raf.readByte() != 0)
    count++;

  raf.seek(filePos);
  String result = raf.readString(count);
  raf.readByte(); // skip the zero byte! nn
  return result;
}
 
Example 5
Source File: H5header.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Read a zero terminated String. Leave file positioned after zero terminator byte.
 *
 * @param raf from this file
 * @return String (dont include zero terminator)
 * @throws java.io.IOException on io error
 */
private String readString(RandomAccessFile raf) throws IOException {
  long filePos = raf.getFilePointer();

  int count = 0;
  while (raf.readByte() != 0)
    count++;

  raf.seek(filePos);
  String result = raf.readString(count);
  raf.readByte(); // skip the zero byte! nn
  return result;
}
 
Example 6
Source File: GRIB2DataInfo.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private int readSectionNumber(RandomAccessFile br) throws IOException {
    byte[] bytes = br.readBytes(4);
    if (new String(bytes).trim().equals("GRIB")) {
        br.seek(br.getFilePointer() - 4);
        return 0;
    } else if (bytes[0] == '7' && bytes[1] == '7' && bytes[2] == '7' && bytes[3] == '7') {
        br.seek(br.getFilePointer() - 4);
        return 8;
    } else {
        int sectionNum = br.readByte();
        br.seek(br.getFilePointer() - 5);
        return sectionNum;
    }
}
 
Example 7
Source File: Cinrad2Record.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void readCC20Header(RandomAccessFile din) throws IOException {

    message_offset = 0;
    din.seek(message_offset);
    // site info 170
    din.skipBytes(62);

    // Message Header
    String stationId = din.readString(40);
    String stationNbr = din.readString(10);

    din.skipBytes(20);

    String clon = din.readString(16);
    String clat = din.readString(16);
    // latlon
    int lon = din.readInt();
    int lat = din.readInt();
    int hhh = din.readInt();

    din.skipBytes(40);

    // ObservationInfo
    short scanMode = convertunsignedByte2Short(din.readByte());
    if (scanMode == 10) {
      sweepN = 1;
    } else if (scanMode >= 100) {
      sweepN = scanMode - 100;
    } else {
      throw new IOException("Error reading CINRAD CC data: Unsupported product: RHI/FFT");
    }

    short syear = (short) din.readUnsignedShort();
    short smm = convertunsignedByte2Short(din.readByte());
    short sdd = convertunsignedByte2Short(din.readByte());
    short shh = convertunsignedByte2Short(din.readByte());
    short smi = convertunsignedByte2Short(din.readByte());
    short sss = convertunsignedByte2Short(din.readByte());

    dateTime0 = CalendarDate.of(null, syear, smm, sdd, shh, smi, sss);

    din.skipBytes(14); // 14+ (35 - 21)

    // remain2[660]
    elev = new int[sweepN];
    recordNum = new int[sweepN];
    for (int i = 0; i < sweepN; i++) {
      din.skipBytes(14);
      int zbinWidth = din.readUnsignedShort();
      int vbinWidth = din.readUnsignedShort();
      int sbinWidth = din.readUnsignedShort();
      int zbinNum = din.readUnsignedShort();
      int vbinNum = din.readUnsignedShort();
      int sbinNum = din.readUnsignedShort();
      recordNum[i] = din.readUnsignedShort();
      // if(i > 0)
      // recordNum[i] = recordNum[i] + recordNum[i-1];
      elev[i] = din.readShort();
      cDataForm = din.readByte();
      if (cDataForm != 22 && cDataForm != 23 && cDataForm != 24)
        throw new IOException("Unsupported CC data format");
      int dataP = din.readInt();
      // din.skipBytes(2);
      // System.out.println("zbin num: " + zbinNum + " vbin num: " + vbinNum + " sbin num: " + sbinNum + " dataForm " +
      // cDataForm);
    }

    for (int i = sweepN; i < 32; i++) {
      din.skipBytes(35);
    }

    din.skipBytes(6);

    syear = (short) din.readUnsignedShort();
    smm = convertunsignedByte2Short(din.readByte());
    sdd = convertunsignedByte2Short(din.readByte());
    shh = convertunsignedByte2Short(din.readByte());
    smi = convertunsignedByte2Short(din.readByte());
    sss = convertunsignedByte2Short(din.readByte());

    dateTimeE = CalendarDate.of(null, syear, smm, sdd, shh, smi, sss);

  }