本文整理汇总了Java中ucar.unidata.io.RandomAccessFile.readFully方法的典型用法代码示例。如果您正苦于以下问题:Java RandomAccessFile.readFully方法的具体用法?Java RandomAccessFile.readFully怎么用?Java RandomAccessFile.readFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ucar.unidata.io.RandomAccessFile
的用法示例。
在下文中一共展示了RandomAccessFile.readFully方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Grib2SectionLocalUse
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read Grib2SectionLocalUse from raf.
*
* @param raf RandomAccessFile, with pointer at start od section
* @throws java.io.IOException on I/O error
*/
public Grib2SectionLocalUse(RandomAccessFile raf) throws IOException {
// octets 1-4 (Length of GDS)
int length = GribNumbers.int4(raf);
int section = raf.read(); // This is section 2
if (section != 2) { // no local use section
length = 0;
raf.skipBytes(-5);
rawData = null;
return;
} else {
rawData = new byte[length-5];
raf.readFully(rawData);
}
}
示例3: Grib2SectionIndicator
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read Grib2SectionIndicator from raf.
*
* @param raf RandomAccessFile, with pointer at start (the "GRIB")
* @throws java.io.IOException on I/O error
* @throws IllegalArgumentException if not a GRIB-2 record
*/
public Grib2SectionIndicator(RandomAccessFile raf) throws IOException {
startPos = raf.getFilePointer();
byte[] b = new byte[4];
raf.readFully(b);
// 判断是不是GRIB
for (int i = 0; i < b.length; i++) {
if (b[i] != MAGIC[i])
throw new IllegalArgumentException("Not a GRIB record");
}
raf.skipBytes(2);
discipline = raf.read();
int edition = raf.read();
if (edition != 2)
throw new IllegalArgumentException("Not a GRIB-2 record");
messageLength = GribNumbers.int8(raf);
}
示例4: 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);
}
示例5: Grib1SectionGridDefinition
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 Grib1SectionGridDefinition(RandomAccessFile raf) throws IOException {
startingPosition = raf.getFilePointer();
// octets 1-3 (Length of GDS)
int length = GribNumbers.int3(raf);
// octet 6
raf.skipBytes(2);
gridTemplate = GribNumbers.uint(raf);
// read in whole GDS as byte[]
rawData = new byte[length];
raf.seek(startingPosition);
raf.readFully(rawData);
predefinedGridDefinition = -1;
predefinedGridDefinitionCenter = -1;
}
示例6: getBitmap
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read the bit map array.
*
* @param raf read from here
* @return bit map as array of byte values
* @throws java.io.IOException on read error
*/
public byte[] getBitmap(RandomAccessFile raf) throws IOException {
// no bitMap
if (bitMapIndicator == 255)
return null;
// LOOK: bitMapIndicator=254 == previously defined bitmap
if (bitMapIndicator == 254)
// logger.debug("HEY bitMapIndicator=254 previously defined bitmap");
if (bitMapIndicator != 0) {
throw new UnsupportedOperationException("Grib2 Bit map section pre-defined (provided by center) = " + bitMapIndicator);
}
raf.seek(startingPosition);
int length = GribNumbers.int4(raf);
raf.skipBytes(2);
byte[] data = new byte[length - 6];
raf.readFully(data);
return data;
/* create new bit map when it is first asked for
boolean[] bitmap = new boolean[numberOfPoints];
int[] bitmask = {128, 64, 32, 16, 8, 4, 2, 1};
for (int i = 0; i < bitmap.length; i++) {
bitmap[i] = (data[i / 8] & bitmask[i % 8]) != 0;
}
return bitmap; */
}
示例7: Grib1SectionIndicator
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read Grib2SectionIndicator from raf.
*
* @param raf RandomAccessFile, with pointer at start (the "GRIB")
* @throws java.io.IOException on I/O error
* @throws IllegalArgumentException if not a GRIB-2 record
*/
public Grib1SectionIndicator(RandomAccessFile raf) throws IOException {
startPos = raf.getFilePointer();
byte[] b = new byte[4];
raf.readFully(b);
for (int i = 0; i < b.length; i++)
if (b[i] != MAGIC[i])
throw new IllegalArgumentException("Not a GRIB record");
messageLength = GribNumbers.uint3(raf);
int edition = raf.read();
if (edition != 1)
throw new IllegalArgumentException("Not a GRIB-1 record");
}
示例8: 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;
}
示例9: getData41
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
public float[] getData41(RandomAccessFile raf, Grib2Drs.Type0 gdrs) throws IOException {
int nb = gdrs.numberOfBits;
int D = gdrs.decimalScaleFactor;
float DD = (float) java.lang.Math.pow((double) 10, (double) D);
float R = gdrs.referenceValue;
int E = gdrs.binaryScaleFactor;
float EE = (float) java.lang.Math.pow( 2.0, (double) E);
// LOOK: can # datapoints differ from bitmap and data ?
// dataPoints are number of points encoded, it could be less than the
// totalNPoints in the grid record if bitMap is used, otherwise equal
float[] data = new float[totalNPoints];
// no data to decode, set to reference value
if (nb == 0) {
Arrays.fill(data, R);
return data;
}
// Y * 10**D = R + (X1 + X2) * 2**E
// E = binary scale factor
// D = decimal scale factor
// R = reference value
// X1 = 0
// X2 = scaled encoded value
// data[ i ] = (R + ( X1 + X2) * EE)/DD ;
byte[] buf = new byte[dataLength - 5];
raf.readFully(buf);
InputStream in = new ByteArrayInputStream(buf);
BufferedImage image = ImageIO.read(in);
if (nb != image.getColorModel().getPixelSize()){
//log.debug("PNG pixel size disagrees with grib number of bits: ",image.getColorModel().getPixelSize(), nb);
}
DataBuffer db = image.getRaster().getDataBuffer();
if (bitmap == null) {
for (int i = 0; i < dataNPoints; i++) {
// data[i] = (R + imageData[i] * EE) / DD;
data[i] = (R + db.getElem(i) * EE) / DD;
}
} else {
for (int bitPt = 0, dataPt = 0; bitPt < totalNPoints; bitPt++) {
if ((bitmap[bitPt / 8] & GribNumbers.bitmask[bitPt % 8]) != 0) {
// data[i] = (R + imageData[i] * EE) / DD;
data[bitPt] = (R + db.getElem(dataPt++) * EE) / DD;
} else {
data[bitPt] = staticMissingValue;
}
}
}
return data;
}
示例10: getBitmap
import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Read the bitmap array when needed
*/
public byte[] getBitmap(RandomAccessFile raf) throws IOException {
if (startingPosition <= 0) {
throw new IllegalStateException("Grib1 Bit map has bad starting position");
}
raf.seek(startingPosition);
// octet 1-3 (length of section)
int length = GribNumbers.uint3(raf);
// octet 4 unused bits
raf.read(); // unused
// octets 5-6
int bm = raf.readShort();
if (bm != 0) {
//logger.warn("Grib1 Bit map section pre-defined (provided by center) bitmap number = {}", bm);
return null;
}
// not sure if length is set correctly when pre-define bitmap is used, so wait until that to test
// seeing a -1, bail out
if (length <= 6 || length > 10e6) { // look max ??
return null;
}
// read the bits as integers
int n = length - 6;
byte[] data = new byte[n];
raf.readFully(data);
return data;
// create new bit map, octet 4 contains number of unused bits at the end
/* boolean[] bitmap = new boolean[n * 8 - unused]; // should be
boolean[] bitmap = new boolean[n * 8]; //
// fill bit map
int count = 0;
int[] bitmask = {128, 64, 32, 16, 8, 4, 2, 1};
for (int i = 0; i < bitmap.length; i++) {
bitmap[i] = (data[i / 8] & bitmask[i % 8]) != 0;
if (bitmap[i]) count++;
}
float r = (float) count / 8 / n;
System.out.printf("bitmap count = %d / %d (%f)%n", count, 8*n, r);
return bitmap; */
}
示例11: 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[length];
raf.readFully(data);
return data;
}
示例12: Grib1SectionProductDefinition
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 Grib1SectionProductDefinition(RandomAccessFile raf) throws IOException {
int length = GribNumbers.uint3(raf);
rawData = new byte[length];
raf.skipBytes(-3);
raf.readFully(rawData);
}