当前位置: 首页>>代码示例>>Java>>正文


Java RandomAccessFile.seek方法代码示例

本文整理汇总了Java中ucar.unidata.io.RandomAccessFile.seek方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.seek方法的具体用法?Java RandomAccessFile.seek怎么用?Java RandomAccessFile.seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ucar.unidata.io.RandomAccessFile的用法示例。


在下文中一共展示了RandomAccessFile.seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Grib2SectionProductDefinition

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read Product Definition section from raf.
*
* @param raf RandomAccessFile, with pointer at start of section
* @throws java.io.IOException on I/O error
* @throws IllegalArgumentException if not a GRIB-2 record
*/
public Grib2SectionProductDefinition( RandomAccessFile raf) throws IOException {

  long startingPosition = raf.getFilePointer();

  // octets 1-4 (Length of GDS)
  int length = GribNumbers.int4(raf);

 // octet 5
  int section = raf.read();
  if (section != 4)
    throw new IllegalArgumentException("Not a GRIB-2 PDS section");

  // octets 8-9
  raf.skipBytes(2);
  templateNumber = GribNumbers.int2(raf);

  // read in whole GDS as byte[]
  rawData = new byte[length];
  raf.seek(startingPosition);
  raf.readFully(rawData);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:29,代码来源:Grib2SectionProductDefinition.java

示例2: isValidFile

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
static public boolean isValidFile(RandomAccessFile raf) {
  try {
    raf.seek(0);
    boolean found = raf.searchForward(matcher, maxScan); // look in first 16K
    if (!found) return false;
    raf.skipBytes(4); // will be positioned on byte 0 of indicator section
    int len = GribNumbers.uint3(raf);
    int edition = raf.read(); // read at byte 8
    if (edition != 1) return false;

    // check ending = 7777
    if (len > raf.length()) return false;
    if (allowBadIsLength) return true;

    raf.skipBytes(len-12);
    for (int i = 0; i < 4; i++) {
      if (raf.read() != 55) return false;
    }
    return true;

  } catch (IOException e) {
    return false;
  }
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:25,代码来源:Grib1RecordScanner.java

示例3: Grib2SectionGridDefinition

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Read Grib Definition section from raf.
 *
 * @param raf RandomAccessFile, with pointer at start of section
 * @throws java.io.IOException on I/O error
 * @throws IllegalArgumentException if not a GRIB-2 record
 */
public Grib2SectionGridDefinition(RandomAccessFile raf) throws IOException {

  startingPosition = raf.getFilePointer();

  // octets 1-4 (Length of GDS)
  int length = GribNumbers.int4(raf);

 // octet 5
  int section = raf.read();  // This is section 3
  if (section != 3)
    throw new IllegalArgumentException("Not a GRIB-2 GDS section");

  // octets 13-14
  raf.skipBytes(7);
  templateNumber = GribNumbers.uint2(raf);

  // read in whole GDS as byte[]
  rawData = new byte[length];
  raf.seek(startingPosition);
  raf.readFully(rawData);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:29,代码来源:Grib2SectionGridDefinition.java

示例4: readData

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Read data array
 *
 * @param raf    from this RandomAccessFile
 * @param drsPos Grib2SectionDataRepresentation starts here
 * @return data as float[] array
 * @throws IOException on read error
 */
public float[] readData(RandomAccessFile raf, long drsPos) throws IOException {
	raf.seek(drsPos);
	Grib2SectionDataRepresentation drs = new Grib2SectionDataRepresentation(raf);//5
	Grib2SectionBitMap bms = new Grib2SectionBitMap(raf);
	Grib2SectionData dataSection = new Grib2SectionData(raf);

	Grib2Gds gds = getGDS();
	Grib2DataReader2 reader = new Grib2DataReader2(drs.getDataTemplate(), gdss.getNumberPoints(), drs.getDataPoints(), getScanMode(), gds.getNxRaw(), dataSection.getStartingPosition(), dataSection.getMsgLength());

	Grib2Drs gdrs = drs.getDrs(raf);

	float[] data = reader.getData(raf, bms, gdrs);

	if (gds.isThin())
		data = QuasiRegular.convertQuasiGrid(data, gds.getNptsInLine(), gds.getNxRaw(), gds.getNyRaw(), GribData.getInterpolationMethod());

	lastRecordRead = this;
	return data;
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:28,代码来源:Grib2Record.java

示例5: Grib2SectionData

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public Grib2SectionData(RandomAccessFile raf) throws IOException {
  startingPosition = raf.getFilePointer();

  // octets 1-4 (Length of section)
  msgLength = GribNumbers.int4(raf);

  // octet 5
  int section = raf.read();
  if (section != 7)
    throw new IllegalStateException("Not a Grib2SectionData (section 7)");

  // skip to end of the data section
  raf.seek(startingPosition + msgLength);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:15,代码来源:Grib2SectionData.java

示例6: Grib2SectionBitMap

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public Grib2SectionBitMap(RandomAccessFile raf) throws IOException {
  startingPosition = raf.getFilePointer();

  // octets 1-4 (Length of section)
  int length = GribNumbers.int4(raf);

  // octet 5
  int section = raf.read();
  if (section != 6)
    throw new IllegalArgumentException("Not a GRIB-2 Bitmap section");

  // octet 6
  bitMapIndicator = raf.read();
  raf.seek(startingPosition + length);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:16,代码来源:Grib2SectionBitMap.java

示例7: Grib1SectionBinaryData

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public Grib1SectionBinaryData(RandomAccessFile raf) throws IOException {
  startingPosition = raf.getFilePointer();

  // octets 1-3 (Length of section)
  length = GribNumbers.uint3(raf);
  //if (length < 0)
  //  throw new IllegalStateException("GRIB record has bad length, pos = " + startingPosition);
  raf.seek(startingPosition + length);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:10,代码来源:Grib1SectionBinaryData.java

示例8: Grib1SectionBitMap

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public Grib1SectionBitMap(RandomAccessFile raf) throws IOException {
  startingPosition = raf.getFilePointer();

  // octets 1-3 (Length of section)
  int length = GribNumbers.int3(raf);

  raf.seek(startingPosition + length);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:9,代码来源:Grib1SectionBitMap.java

示例9: getDataRaw

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
int[] getDataRaw(RandomAccessFile raf, byte[] bitmap) throws IOException {
    raf.seek(startPos); // go to the data section
    int msgLength = GribNumbers.uint3(raf);

    // octet 4, 1st half (packing flag)
    int unusedbits = raf.read();
    if ((unusedbits & 192) != 0) {
        // logger.error(
        // "Grib1BinaryDataSection: (octet 4, 1st half) not grid point data and simple packing for {} len={}",
        // raf.getLocation(), msgLength);
        throw new IllegalStateException(
                "Grib1BinaryDataSection: (octet 4, 1st half) not grid point data and simple packing ");
    }

    GribNumbers.int2(raf); // octets 5-6 (binary scale factor)
    GribNumbers.float4(raf); // octets 7-10 (reference point = minimum
                             // value)

    // octet 11 (number of bits per value)
    int numbits = raf.read();
    // boolean isConstant = (numbits == 0);

    // *** read int values
    // *******************************************************
    BitReader reader = new BitReader(raf, startPos + 11);
    int[] ivals = new int[nPts];
    for (int i = 0; i < nPts; i++) {
        ivals[i] = (int) reader.bits2UInt(numbits);
    }

    return ivals;
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:33,代码来源:Grib1DataReader.java

示例10: check

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public void check(RandomAccessFile raf, Formatter f) throws IOException {
	long messLen = is.getMessageLength();
	long startPos = is.getStartPos();
	long endPos = is.getEndPos();

	if (endPos > raf.length()) {
		f.format("End of GRIB message (start=%d len=%d) end=%d > file.length=%d for %s%n", startPos, messLen, endPos, raf.length(), raf.getLocation());
		return;
	}

	raf.seek(endPos - 4);
	for (int i = 0; i < 4; i++) {
		if (raf.read() != 55) {
			String clean = StringUtil2.cleanup(header);
			if (clean.length() > 40)
				clean = clean.substring(0, 40) + "...";
			f.format("Missing End of GRIB message (start=%d len=%d) end=%d header= %s for %s (len=%d)%n", startPos, messLen, endPos, clean, raf.getLocation(), raf.length());
			break;
		}
	}

	long dataLen = dataSection.getMsgLength();
	long dataStart = dataSection.getStartingPosition();
	long dataEnd = dataStart + dataLen;

	if (dataEnd > raf.length()) {
		f.format("GRIB data section (start=%d len=%d) end=%d > file.length=%d for %s%n", dataStart, dataLen, dataEnd, raf.length(), raf.getLocation());
		return;
	}

	if (dataEnd > endPos) {
		f.format("GRIB data section (start=%d len=%d) end=%d > message end=%d for %s%n", dataStart, dataLen, dataEnd, endPos, raf.getLocation());
	}

}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:36,代码来源:Grib2Record.java

示例11: readSectionNumber

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:15,代码来源:GRIB2DataInfo.java

示例12: seekNextSction

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
private void seekNextSction(RandomAccessFile br) {
    try {
        int length = Bytes2Number.int4(br.getRandomAccessFile());
        br.seek(br.getFilePointer() + length - 4);
    } catch (IOException ex) {
        Logger.getLogger(GRIB2DataInfo.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:9,代码来源:GRIB2DataInfo.java

示例13: getBytes

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public byte[] getBytes(RandomAccessFile raf) throws IOException {
  raf.seek(startingPosition); // go to the data section
  byte[] data = new byte[msgLength];
  raf.readFully(data);
  return data;
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:7,代码来源:Grib2SectionData.java

示例14: Grib1RecordScanner

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public Grib1RecordScanner(RandomAccessFile raf) throws IOException {
  this.raf = raf;
  raf.seek(0);
  raf.order(RandomAccessFile.BIG_ENDIAN);
  lastPos = 0;
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:7,代码来源:Grib1RecordScanner.java

示例15: getLength

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
int getLength(RandomAccessFile raf) throws IOException {
  raf.seek(startingPosition);
  return GribNumbers.int4(raf);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:5,代码来源:Grib2SectionBitMap.java


注:本文中的ucar.unidata.io.RandomAccessFile.seek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。