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


Java RandomAccessFile.read方法代码示例

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


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

示例1: 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

示例2: int8

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Convert 8 bytes into a signed long.
 *
 * @param raf RandomAccessFile
 * @return long value
 * @throws IOException on read error
 */
public static long int8(RandomAccessFile raf) throws IOException {
    int a = raf.read();
    int b = raf.read();
    int c = raf.read();
    int d = raf.read();
    int e = raf.read();
    int f = raf.read();
    int g = raf.read();
    int h = raf.read();

    return (1 - ((a & 128) >> 6))
            * ((long) (a & 127) << 56 | (long) b << 48 | (long) c << 40 | (long) d << 32
                    | e << 24 | f << 16 | g << 8 | h);

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

示例3: 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

示例4: Grib2SectionDataRepresentation

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

  // octets 1-4 (Length of DRS)
  length = GribNumbers.int4(raf);
  if (length == 0)
    throw new IllegalArgumentException("Not a GRIB-2 Data representation section");

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

  // octets 6-9 number of datapoints
  dataPoints = GribNumbers.int4(raf);

  // octet 10-11
  int dt = GribNumbers.uint2(raf);
  dataTemplate = (dt == 40000) ? 40 : dt; // ?? NCEP bug ??

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

示例5: 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

示例6: 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(7); // will be positioned on byte 0 of indicator section
		int edition = raf.read(); // read at byte 8
		if (edition != 2)
			return false;

		// check ending = 7777
		long len = GribNumbers.int8(raf);
		if (len > raf.length())
			return false;
		raf.skipBytes(len - 20);
		for (int i = 0; i < 4; i++) {
			if (raf.read() != 55)
				return false;
		}
		return true;

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

示例7: 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);
  }
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:23,代码来源:Grib2SectionLocalUse.java

示例8: 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);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:26,代码来源:Grib2SectionIndicator.java

示例9: 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");
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:21,代码来源:Grib1SectionIndicator.java

示例10: int3

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
 * Convert 3 bytes into a signed integer.
 *
 * @param raf read from here
 * @return integer value
 * @throws IOException on read error
 */
public static int int3(RandomAccessFile raf) throws IOException {
    int a = raf.read();
    int b = raf.read();
    int c = raf.read();

    return int3(a, b, c);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:15,代码来源:GribNumbers.java

示例11: float4

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
/**
* Convert 4 bytes into a float value.
*
* @param raf read from here
* @return float value
* @throws IOException on read error
*/
public static float float4(RandomAccessFile raf) throws IOException {
    int a = raf.read();
    int b = raf.read();
    int c = raf.read();
    int d = raf.read();

    return float4(a, b, c, d);
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:16,代码来源:GribNumbers.java

示例12: 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

示例13: Type0

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
Type0(RandomAccessFile raf) throws IOException {
  this.referenceValue = raf.readFloat();
  this.binaryScaleFactor = GribNumbers.int2(raf);
  this.decimalScaleFactor = GribNumbers.int2(raf);
  this.numberOfBits = raf.read();
  this.originalType = raf.read();
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:8,代码来源:Grib2Drs.java

示例14: Type2

import ucar.unidata.io.RandomAccessFile; //导入方法依赖的package包/类
Type2(RandomAccessFile raf) throws IOException {
  super(raf);
  this.splittingMethod = raf.read();
  this.missingValueManagement = raf.read();
  this.primaryMissingValue = raf.readFloat();
  this.secondaryMissingValue = raf.readFloat();
  this.numberOfGroups = GribNumbers.int4(raf);
  this.referenceGroupWidths = raf.read();
  this.bitsGroupWidths = raf.read();
  this.referenceGroupLength = GribNumbers.int4(raf);
  this.lengthIncrement = raf.read();
  this.lengthLastGroup = GribNumbers.int4(raf);
  this.bitsScaledGroupLength = raf.read();
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:15,代码来源:Grib2Drs.java

示例15: 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


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