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

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

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

RandomAccessFile.length介绍

[英]Get the length of the file. The data in the buffer (which may not have been written the disk yet) is taken into account.
[中]获取文件的长度。缓冲区中的数据(可能尚未写入磁盘)将被考虑在内。

代码示例

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

  1. SeqIter(StructureDataRegexp.Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) vinfo.rafile.length();
  4. vinfo.rafile.seek(0);
  5. }

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

  1. public static Cinrad2Record factory(RandomAccessFile din, int record) throws IOException {
  2. long offset = record * RADAR_DATA_SIZE + FILE_HEADER_SIZE;
  3. if (offset >= din.length())
  4. return null;
  5. else
  6. return new Cinrad2Record(din, record);
  7. }
  8. int getUInt( byte[] b, int num )

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

  1. SeqIter(StructureDataRegexp.Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) vinfo.rafile.length();
  4. vinfo.rafile.seek(0);
  5. }

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

  1. /**
  2. * Create a new one
  3. *
  4. * @throws IOException problem reading the file
  5. */
  6. SeqIter() throws IOException {
  7. totalBytes = (int) raf.length();
  8. raf.seek(0);
  9. }

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

  1. public static Level2Record factory(RandomAccessFile din, int record, long message_offset31) throws IOException {
  2. long offset = record * RADAR_DATA_SIZE + FILE_HEADER_SIZE + message_offset31;
  3. if (offset >= din.length())
  4. return null;
  5. else
  6. return new Level2Record(din, record, message_offset31);
  7. }

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

  1. /**
  2. * Create a new one
  3. *
  4. * @throws IOException problem reading the file
  5. */
  6. SeqIter() throws IOException {
  7. totalBytes = (int) raf.length();
  8. raf.seek(0);
  9. }

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

  1. SeqIter(StructureDataRegexp.Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) vinfo.rafile.length();
  4. vinfo.rafile.seek(0);
  5. }

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

  1. SeqIter(Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) raf.length();
  4. vinfo.raf.seek(0);
  5. }

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

  1. public static Cinrad2Record factory(RandomAccessFile din, int record) throws IOException {
  2. long offset = (long)record * RADAR_DATA_SIZE + FILE_HEADER_SIZE;
  3. if (offset >= din.length())
  4. return null;
  5. else
  6. return new Cinrad2Record(din, record);
  7. }

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

  1. StationSeqIter(StructureDataRegexp.Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) vinfo.rafile.length();
  4. vinfo.rafile.seek(0);
  5. }

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

  1. @Override
  2. public String getDetailInfo() {
  3. if (raf == null) return "";
  4. try {
  5. Formatter fout = new Formatter();
  6. double size = raf.length() / (1000.0 * 1000.0);
  7. fout.format(" raf = %s%n", raf.getLocation());
  8. fout.format(" size= %d (%s Mb)%n%n", raf.length(), Format.dfrac(size, 3));
  9. return fout.toString();
  10. } catch (IOException e) {
  11. return e.getMessage();
  12. }
  13. }

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

  1. @Override
  2. public String getDetailInfo() {
  3. if (raf == null) return "";
  4. try {
  5. Formatter fout = new Formatter();
  6. double size = raf.length() / (1000.0 * 1000.0);
  7. fout.format(" raf = %s%n", raf.getLocation());
  8. fout.format(" size= %d (%s Mb)%n%n", raf.length(), Format.dfrac(size, 3));
  9. return fout.toString();
  10. } catch (IOException e) {
  11. return e.getMessage();
  12. }
  13. }

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

  1. SeqIter(Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) raf.length();
  4. vinfo.raf.seek(0);
  5. }

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

  1. StationSeqIter(StructureDataRegexp.Vinfo vinfo) throws IOException {
  2. this.vinfo = vinfo;
  3. totalBytes = (int) vinfo.rafile.length();
  4. vinfo.rafile.seek(0);
  5. }

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

  1. private void init() {
  2. if (!exists) return;
  3. try {
  4. if (dataRaf != null)
  5. this.timeSeriesRaf = dataRaf; // single station case - data file already open
  6. else
  7. this.timeSeriesRaf = RandomAccessFile.acquire(file.getPath());
  8. totalBytes = timeSeriesRaf.length();
  9. timeSeriesRaf.seek(0);
  10. } catch (IOException e) {
  11. throw new RuntimeException(e);
  12. }
  13. }

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

  1. public byte[] getData(int offset) throws IOException {
  2. int readLen = (int) raf.length();
  3. byte[] b = new byte[readLen];
  4. int pos = 0;
  5. raf.seek(pos);
  6. raf.readFully(b);
  7. return b;
  8. }

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

  1. public byte[] getData(int offset) throws Exception {
  2. int readLen = (int) raf.length();
  3. byte[] b = new byte[readLen];
  4. int pos = 0;
  5. raf.seek(pos);
  6. int rc = raf.read(b);
  7. return b;
  8. }

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

  1. private Array readData(ucar.nc2.Variable v2, long dataPos, List<Range> ranges,
  2. int[] levels) throws IOException, InvalidRangeException {
  3. // Get to the proper offset and read in the data
  4. raf.seek(dataPos);
  5. int data_size = (int) (raf.length() - dataPos);
  6. byte[] data = new byte[data_size];
  7. raf.readFully(data);
  8. // Turn it into an array
  9. Array array = makeArray(data, levels, v2.getShape());
  10. return array.sectionNoReduce(ranges);
  11. }

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

  1. static public boolean isValidFile(RandomAccessFile raf) throws IOException {
  2. raf.seek(0);
  3. if (!raf.searchForward(matcher, 8000)) return false; // must find "GRIB" in first 8k
  4. raf.skipBytes(4);
  5. // Read Section 0 Indicator Section to get Edition number
  6. Grib2IndicatorSection is = new Grib2IndicatorSection(raf); // section 0
  7. if (is.getGribEdition() != 1 && is.getGribEdition() != 2)
  8. return false;
  9. if (is.getGribLength() > raf.length())
  10. return false;
  11. return true;
  12. }

相关文章