• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RandomAccessFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: record_count_is_correct

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
/**
 * @throws Exception
 */
@Test
public void record_count_is_correct() throws Exception {

  //given
  GribFileAccess grib = new GribFileAccess();
  grib.setInputDirectory(new File(IN));

  //when
  List<RandomAccessFile> validGribFiles = grib.getRafFiles();

  //then
  for (RandomAccessFile gribFile : validGribFiles) {
    List<Grib2Record> records = grib.getRecords(gribFile);
    if (gribFile.getLocation().endsWith(FILE_2p5_f000)) {
      assertEquals(321, records.size());
    } else if (gribFile.getLocation().endsWith(FILE_1p0_f003)) {
      assertEquals(365, records.size());
    } else if (gribFile.getLocation().endsWith(FILE_2p5_f006)) {
      assertEquals(365, records.size());
    } else {
      fail("test file not registered: " + gribFile.getLocation());
    }

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


示例17: write

import ucar.unidata.io.RandomAccessFile; //导入依赖的package包/类
private void write(RandomAccessFile raf, Grib2Input input, Options options) throws IOException {
    JsonGenerator jg = newJsonGenerator(options);
    jg.writeStartArray();

    List<Grib2Record> records = input.getRecords();
    for (Grib2Record record : records) {
        GribRecordWriter rw = new GribRecordWriter(jg, record, options);
        if (rw.isSelected()) {
            jg.writeStartObject();
            rw.writeHeader();
            if (options.getPrintData()) {
                rw.writeData(new Grib2Data(raf));
            }
            jg.writeEnd();
        }
    }

    jg.writeEnd();
    jg.close();
}
 
开发者ID:cambecc,项目名称:grib2json,代码行数:21,代码来源:Grib2Json.java


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


示例19: int4

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

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


示例20: uint3

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

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IClassFileReader类代码示例发布时间:2022-05-22
下一篇:
Java CometFilter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap