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


Java RandomAccessFile类代码示例

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


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

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

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

示例3: factory

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
public static Grib2Drs factory(int template, RandomAccessFile raf) throws IOException {
  switch (template) {
    case 0:
    case 41:
      return new Type0(raf);
    case 2:
      return new Type2(raf);
    case 3:
      return new Type3(raf);
    case 40:
      return new Type40(raf);
    //case 51:    //
    //  return new Type51(raf);
    case 50002: // ECMWF's second order packing
  	  return new Type50002(raf);
    default:
      throw new UnsupportedOperationException("Unsupported DRS type = " + template);
  }
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:20,代码来源:Grib2Drs.java

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

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

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

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

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

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

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

示例11: readData

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
private float[] readData(RandomAccessFile raf, GribData.InterpolationMethod method)
        throws IOException {
    Grib1Gds gds = getGDS();
    Grib1DataReader reader =
            new Grib1DataReader(pdss.getDecimalScale(), gds.getScanMode(), gds.getNxRaw(),
                    gds.getNyRaw(), gds.getNpts(), dataSection.getStartingPosition());
    byte[] bm = (bitmap == null) ? null : bitmap.getBitmap(raf);
    float[] data = reader.getData(raf, bm);

    if (gdss.isThin()) {
        data =
                QuasiRegular.convertQuasiGrid(data, gds.getNptsInLine(), gds.getNxRaw(),
                        gds.getNyRaw(), method);
    }

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

示例12: getData

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
public float[] getData(RandomAccessFile raf, byte[] bitmap) throws IOException {
    GribData.Info info = Grib1SectionBinaryData.getBinaryDataInfo(raf, startPos);

    boolean isGridPointData = !GribNumbers.testBitIsSet(info.flag, 1);
    boolean isSimplePacking = !GribNumbers.testBitIsSet(info.flag, 2);

    if (isGridPointData && isSimplePacking) {
        return readSimplePacking(raf, bitmap, info);
    }

    if (isGridPointData && !isSimplePacking) {
        return readExtendedComplexPacking(raf, bitmap, info);
    }

    // logger.warn("Grib1BinaryDataSection: (octet 4, 1st half) not grid point data and simple packing for {}",
    // raf.getLocation());
    throw new IllegalStateException(
            "Grib1BinaryDataSection: (octet 4, 1st half) not grid point data and simple packing ");
}
 
开发者ID:0nirvana0,项目名称:grib2reader,代码行数:20,代码来源:Grib1DataReader.java

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

示例14: getRafFiles

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
/**
 * @return
 * @throws Exception
 */
public List<RandomAccessFile> getRafFiles() throws Exception {
  LOGGER.info("start scanning folder " + inputDirectory.getAbsolutePath());
  List<RandomAccessFile> validRafFiles = new ArrayList<RandomAccessFile>();
  File[] files = inputDirectory.listFiles();
  if (files == null || files.length == 0) {
    return validRafFiles;
  }

  for (File file : files) {
    RandomAccessFile validRaf = getValidGribfile(file);

    if (validRaf != null) {
      LOGGER.info("use " + file.getAbsolutePath());
      validRafFiles.add(validRaf);
    } else {
      LOGGER.info("skip " + file.getAbsolutePath());
    }
  }
  return validRafFiles;
}
 
开发者ID:MeteoGroup,项目名称:grib2geotiff,代码行数:25,代码来源:GribFileAccess.java

示例15: getValidGribfile

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
/**
 * @param file
 * @return
 * @throws Exception
 */
private RandomAccessFile getValidGribfile(File file) throws Exception {
  if (!file.exists()
      || file.isDirectory()
      || file.getName().endsWith(".aux.xml")) {
    return null;
  }
  RandomAccessFile raf = new RandomAccessFile(file.getAbsolutePath(), "r");
  raf.order(RandomAccessFile.BIG_ENDIAN);

  if (Grib2Input.isValidFile(raf)) {
    return raf;
  } else {
    return null;
  }

}
 
开发者ID:MeteoGroup,项目名称:grib2geotiff,代码行数:22,代码来源:GribFileAccess.java


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