本文整理汇总了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);
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
}
示例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;
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例15: getLength
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
int getLength(RandomAccessFile raf) throws IOException {
raf.seek(startingPosition);
return GribNumbers.int4(raf);
}