Java Code Examples for ucar.unidata.io.RandomAccessFile#order()
The following examples show how to use
ucar.unidata.io.RandomAccessFile#order() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Vis5DIosp.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Is this a valid file? * * @param raf RandomAccessFile to check * @return true if a valid McIDAS AREA file * @throws IOException problem reading file */ public boolean isValidFile(RandomAccessFile raf) throws IOException { // quick test raf.order(RandomAccessFile.BIG_ENDIAN); raf.seek(0); String got = raf.readString(V5D.length()); if (got.equals(V5D)) { return true; } else { // more rigorous test V5DStruct vv; try { vv = V5DStruct.v5dOpenFile(raf); } catch (BadFormException bfe) { vv = null; } return vv != null; } }
Example 2
Source File: H5iospNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { super.open(raf, rootGroup.getNcfile(), cancelTask); raf.order(RandomAccessFile.BIG_ENDIAN); header = new H5headerNew(raf, rootGroup, this); header.read(null); // check if its an HDF5-EOS file if (useHdfEos) { rootGroup.findGroupLocal(HdfEos.HDF5_GROUP).ifPresent(eosGroup -> { try { isEos = HdfEos.amendFromODL(raf.getLocation(), header, eosGroup); } catch (IOException e) { log.warn(" HdfEos.amendFromODL failed"); } }); } }
Example 3
Source File: N3iospNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Deprecated @Override public void open(RandomAccessFile raf, NetcdfFile ncfile, CancelTask cancelTask) throws IOException { super.open(raf, ncfile, cancelTask); String location = raf.getLocation(); if (!location.startsWith("http:")) { File file = new File(location); if (file.exists()) lastModified = file.lastModified(); } raf.order(RandomAccessFile.BIG_ENDIAN); header = createHeader(); Group.Builder rootGroup = Group.builder().setName("").setNcfile(ncfile); header.read(raf, rootGroup, null); ncfile.setRootGroup(rootGroup.build()); ncfile.finish(); }
Example 4
Source File: UAMIVServiceProvider.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Check if this is a valid file for this IOServiceProvider. * * @param raf RandomAccessFile * @return true if valid. */ public boolean isValidFile(RandomAccessFile raf) { try { raf.order(RandomAccessFile.BIG_ENDIAN); raf.seek(0); raf.skipBytes(4); String test = raf.readString(40); return test.equals(EMISSIONS) || test.equals(AVERAGE) || test.equals(AIRQUALITY) || test.equals(INSTANT); } catch (IOException ioe) { return false; } }
Example 5
Source File: Cinrad2IOServiceProvider.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean isValidFile(RandomAccessFile raf) { try { if (isCINRAD(raf)) { Cinrad2Record.MISSING_DATA = (byte) 0; return true; } else { Cinrad2Record.MISSING_DATA = (byte) 1; } raf.order(RandomAccessFile.LITTLE_ENDIAN); raf.seek(0); raf.skipBytes(14); short message_type = raf.readShort(); if (message_type != 1) return false; raf.skipBytes(12); // data header byte[] b4 = raf.readBytes(4); int data_msecs = bytesToInt(b4, true); byte[] b2 = raf.readBytes(2); short data_julian_date = (short) bytesToShort(b2, true); if (data_msecs > 86400000) return false; java.util.Date dd = Cinrad2Record.getDate(data_julian_date, data_msecs); Calendar cal = new GregorianCalendar(new SimpleTimeZone(0, "GMT")); cal.clear(); cal.setTime(dd); int year = cal.get(Calendar.YEAR); cal.setTime(new Date()); int cyear = cal.get(Calendar.YEAR); return year >= 1990 && year <= cyear; } catch (IOException ioe) { return false; } }
Example 6
Source File: Cinrad2IOServiceProvider.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public boolean isCINRAD(RandomAccessFile raf) { int data_msecs = 0; try { raf.order(RandomAccessFile.LITTLE_ENDIAN); raf.seek(0); byte[] b128 = raf.readBytes(136); String radarT = new String(b128); if (radarT.contains("CINRAD/SC") || radarT.contains("CINRAD/CD")) { isSC = true; isCC = false; isCC20 = false; return true; } else if (radarT.contains("CINRADC")) { isCC = true; isSC = false; isCC20 = false; return true; } else if (!radarT.contains("CINRADC") && radarT.contains("CINRAD/CC")) { isCC20 = true; isSC = false; isCC = false; return true; } else { isSC = false; isCC = false; isCC20 = false; return false; } } catch (IOException ioe) { return false; } }
Example 7
Source File: N3iospNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { super.open(raf, rootGroup.getNcfile(), cancelTask); String location = raf.getLocation(); if (!location.startsWith("http:")) { File file = new File(location); if (file.exists()) lastModified = file.lastModified(); } raf.order(RandomAccessFile.BIG_ENDIAN); header = createHeader(); header.read(raf, rootGroup, null); }
Example 8
Source File: H4iosp.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void build(RandomAccessFile raf, Group.Builder rootGroup, CancelTask cancelTask) throws IOException { super.open(raf, rootGroup.getNcfile(), cancelTask); raf.order(RandomAccessFile.BIG_ENDIAN); header = new H4header(this); header.read(raf, rootGroup, null); }
Example 9
Source File: MessageScanner.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public MessageScanner(RandomAccessFile raf, long startPos, boolean useEmbeddedTables) throws IOException { startPos = (startPos < 30) ? 0 : startPos - 30; // look for the header this.raf = raf; lastPos = startPos; this.useEmbeddedTables = useEmbeddedTables; raf.seek(startPos); raf.order(RandomAccessFile.BIG_ENDIAN); }
Example 10
Source File: Grib2RecordScanner.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Grib2RecordScanner(RandomAccessFile raf) throws IOException { this.raf = raf; raf.seek(0); raf.order(RandomAccessFile.BIG_ENDIAN); lastPos = 0; if (debugRepeat) logger.debug(" Grib2RecordScanner {}", raf.getLocation()); }
Example 11
Source File: GribCdmIndex.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean openIndex(RandomAccessFile indexRaf, Logger logger) { try { indexRaf.order(RandomAccessFile.BIG_ENDIAN); indexRaf.seek(0); //// header message byte[] magic = new byte[Grib2CollectionWriter.MAGIC_START.getBytes(StandardCharsets.UTF_8).length]; // they are // all the // same indexRaf.readFully(magic); int version = indexRaf.readInt(); long recordLength = indexRaf.readLong(); if (recordLength > Integer.MAX_VALUE) { logger.error("Grib2Collection {}: invalid recordLength size {}", indexRaf.getLocation(), recordLength); return false; } indexRaf.skipBytes(recordLength); int size = NcStream.readVInt(indexRaf); if ((size < 0) || (size > 100 * 1000 * 1000)) { logger.warn("GribCdmIndex {}: invalid index size {}", indexRaf.getLocation(), size); return false; } byte[] m = new byte[size]; indexRaf.readFully(m); gribCollectionIndex = GribCollectionProto.GribCollection.parseFrom(m); return true; } catch (Throwable t) { logger.error("Error reading index " + indexRaf.getLocation(), t); return false; } }
Example 12
Source File: GempakGridReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private Grib2Record makeGribRecord(RandomAccessFile raf, long start) throws IOException { Grib2SectionIndicator is = new Grib2SectionIndicator(start, 0, 0); // apparently not in GEMPAK file (!) Grib2SectionIdentification ids = null; Grib2SectionLocalUse lus = null; Grib2SectionGridDefinition gds = null; Grib2SectionProductDefinition pds = null; Grib2SectionDataRepresentation drs = null; Grib2SectionBitMap bms = null; Grib2SectionData dataSection = null; raf.seek(start); raf.order(RandomAccessFile.BIG_ENDIAN); int secLength = raf.readInt(); if (secLength > 0) { ids = new Grib2SectionIdentification(raf); } secLength = raf.readInt(); if (secLength > 0) { lus = new Grib2SectionLocalUse(raf); } secLength = raf.readInt(); if (secLength > 0) { gds = new Grib2SectionGridDefinition(raf); } secLength = raf.readInt(); if (secLength > 0) { pds = new Grib2SectionProductDefinition(raf); } secLength = raf.readInt(); if (secLength > 0) { drs = new Grib2SectionDataRepresentation(raf); } secLength = raf.readInt(); if (secLength > 0) { bms = new Grib2SectionBitMap(raf); } secLength = raf.readInt(); if (secLength > 0) { dataSection = new Grib2SectionData(raf); if (dataSection.getMsgLength() > secLength) // presumably corrupt throw new IllegalStateException("Illegal Grib2SectionData Message Length"); } // LOOK - not dealing with repeated records return new Grib2Record(null, is, ids, lus, gds, pds, drs, bms, dataSection, false, Grib2Index.ScanModeMissing); }
Example 13
Source File: BufrCdmIndex.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected boolean readIndex(RandomAccessFile raf) { this.idxFilename = raf.getLocation(); try { raf.order(RandomAccessFile.BIG_ENDIAN); raf.seek(0); //// header message if (!NcStream.readAndTest(raf, MAGIC_START.getBytes(StandardCharsets.UTF_8))) { log.error("BufrCdmIndex {}: invalid index", raf.getLocation()); return false; } int indexVersion = raf.readInt(); boolean versionOk = (indexVersion == version); if (!versionOk) { log.warn("BufrCdmIndex {}: index found version={}, want version= {}", raf.getLocation(), indexVersion, version); return false; } int size = NcStream.readVInt(raf); if ((size < 0) || (size > 100 * 1000 * 1000)) { log.warn("BufrCdmIndex {}: invalid or empty index ", raf.getLocation()); return false; } byte[] m = new byte[size]; raf.readFully(m); BufrCdmIndexProto.BufrIndex proto = BufrCdmIndexProto.BufrIndex.parseFrom(m); bufrFilename = proto.getFilename(); root = proto.getRoot(); stations = proto.getStationsList(); start = proto.getStart(); end = proto.getEnd(); nobs = proto.getNobs(); // showProtoRoot(root); } catch (Throwable t) { log.error("Error reading index " + raf.getLocation(), t); return false; } return true; }
Example 14
Source File: Grib2RecordScanner.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private Grib2RecordScanner(RandomAccessFile raf, long startFrom) throws IOException { this.raf = raf; raf.seek(startFrom); raf.order(RandomAccessFile.BIG_ENDIAN); lastPos = startFrom; }
Example 15
Source File: Grib1RecordScanner.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public Grib1RecordScanner(RandomAccessFile raf) throws IOException { this.raf = raf; raf.seek(0); raf.order(RandomAccessFile.BIG_ENDIAN); lastPos = 0; }
Example 16
Source File: McIDASGridReader.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Initialize the file, read in all the metadata (ala DM_OPEN) * * @param fullCheck for a full check reading grids * @param raf RandomAccessFile to read. * @throws IOException problem reading file */ public final boolean init(RandomAccessFile raf, boolean fullCheck) throws IOException { rf = raf; raf.order(RandomAccessFile.BIG_ENDIAN); return init(fullCheck); }