ucar.unidata.io.RandomAccessFile.acquire()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(339)

本文整理了Java中ucar.unidata.io.RandomAccessFile.acquire方法的一些代码示例,展示了RandomAccessFile.acquire的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RandomAccessFile.acquire方法的具体详情如下:
包路径:ucar.unidata.io.RandomAccessFile
类名称:RandomAccessFile
方法名:acquire

RandomAccessFile.acquire介绍

暂无

代码示例

代码示例来源:origin: Unidata/thredds

  1. @Override
  2. public boolean isPartition(Path indexFile) throws IOException {
  3. if (debug) System.out.printf("GribCdmIndex.isPartition %s%n", indexFile);
  4. try (RandomAccessFile raf = RandomAccessFile.acquire(indexFile.toString())) {
  5. GribCollectionType type = getType(raf);
  6. return (type == GribCollectionType.Partition1) || (type == GribCollectionType.Partition2);
  7. }
  8. }

代码示例来源:origin: Unidata/thredds

  1. public void reacquire() throws IOException {
  2. raf = RandomAccessFile.acquire(location);
  3. this.raf.order(rafOrder);
  4. }

代码示例来源:origin: Unidata/thredds

  1. private void init() {
  2. if (!exists) return;
  3. try {
  4. if (dataRaf != null)
  5. this.timeSeriesRaf = dataRaf; // single station case - data file already open
  6. else
  7. this.timeSeriesRaf = RandomAccessFile.acquire(file.getPath());
  8. totalBytes = timeSeriesRaf.length();
  9. timeSeriesRaf.seek(0);
  10. } catch (IOException e) {
  11. throw new RuntimeException(e);
  12. }
  13. }

代码示例来源:origin: Unidata/thredds

  1. public RandomAccessFile getDataRaf(int fileno) throws IOException {
  2. // absolute location
  3. MFile mfile = fileMap.get(fileno);
  4. String filename = mfile.getPath();
  5. File dataFile = new File(filename);
  6. // if data file does not exist, check reletive location - eg may be /upc/share instead of Q:
  7. if (!dataFile.exists()) {
  8. if (fileMap.size() == 1) {
  9. dataFile = new File(directory, name); // single file case
  10. } else {
  11. dataFile = new File(directory, dataFile.getName()); // must be in same directory as the ncx file
  12. }
  13. }
  14. // data file not here
  15. if (!dataFile.exists()) {
  16. throw new FileNotFoundException("data file not found = " + dataFile.getPath());
  17. }
  18. RandomAccessFile want = RandomAccessFile.acquire(dataFile.getPath());
  19. want.order(RandomAccessFile.BIG_ENDIAN);
  20. return want;
  21. }

代码示例来源:origin: Unidata/thredds

  1. public static BufrCdmIndex readIndex(String indexFilename) throws IOException {
  2. BufrCdmIndex index = new BufrCdmIndex();
  3. try (RandomAccessFile raf = RandomAccessFile.acquire(indexFilename)) {
  4. index.readIndex(raf);
  5. }
  6. return index;
  7. }

代码示例来源:origin: Unidata/thredds

  1. static private boolean isUpdateNeeded(String idxFilenameOrg, CollectionUpdateType updateType, GribCollectionType wantType, Logger logger) {
  2. if (updateType == CollectionUpdateType.never) return false;
  3. // see if index already exists
  4. File collectionIndexFile = GribIndexCache.getExistingFileOrCache(idxFilenameOrg);
  5. if (collectionIndexFile != null) { // it exists
  6. boolean bad;
  7. try (RandomAccessFile raf = RandomAccessFile.acquire(collectionIndexFile.getPath())) { // read it to verify its good
  8. GribCollectionType type = getType(raf);
  9. bad = (type != wantType);
  10. if (!bad && updateType == CollectionUpdateType.nocheck) return false; // use if index is ok
  11. } catch (IOException ioe) {
  12. bad = true;
  13. }
  14. if (bad) { // delete the file and remove from cache if its in there
  15. RandomAccessFile.eject(collectionIndexFile.getPath());
  16. if (!collectionIndexFile.delete())
  17. logger.warn("failed to delete {}", collectionIndexFile.getPath());
  18. }
  19. }
  20. return true;
  21. }

代码示例来源:origin: Unidata/thredds

  1. dataRaf = RandomAccessFile.acquire(base+DAT_EXT);
  2. stnRaf = RandomAccessFile.acquire(base+STN_EXT);
  3. stnRaf = RandomAccessFile.acquire(base+STN_EXT);
  4. dataRaf = RandomAccessFile.acquire(base+DAT_EXT);

代码示例来源:origin: Unidata/thredds

  1. ucar.unidata.io.RandomAccessFile.acquire(canonicalizeUriString(location), bufferSize);

代码示例来源:origin: Unidata/thredds

  1. /**
  2. * This is can only be used for local netcdf-3 files.
  3. *
  4. * @param filename location
  5. * @throws java.io.IOException if error
  6. * @deprecated use NetcdfFile.open( location) or NetcdfDataset.openFile( location)
  7. */
  8. public NetcdfFile(String filename) throws IOException {
  9. this.location = filename;
  10. ucar.unidata.io.RandomAccessFile raf = ucar.unidata.io.RandomAccessFile.acquire(filename);
  11. //ucar.unidata.io.RandomAccessFile raf = new ucar.unidata.io.MMapRandomAccessFile(filename, "r");
  12. this.spi = SPFactory.getServiceProvider();
  13. spi.open(raf, this, null);
  14. finish();
  15. }

代码示例来源:origin: Unidata/thredds

  1. raf = ucar.unidata.io.RandomAccessFile.acquire(uncompressedFileName, buffer_size);
  2. raf = ucar.unidata.io.RandomAccessFile.acquire(uriString, buffer_size);

代码示例来源:origin: Unidata/thredds

  1. public FileCacheable open(DatasetUrl durl, int buffer_size, CancelTask cancelTask, Object iospMessage) throws IOException {
  2. try (RandomAccessFile raf = RandomAccessFile.acquire(durl.trueurl)) {
  3. Partition p = (Partition) iospMessage;
  4. return GribCdmIndex.openGribCollectionFromIndexFile(raf, p.getConfig(), p.getLogger()); // do we know its a partition ?
  5. } catch (Throwable t) {
  6. RandomAccessFile.eject(durl.trueurl);
  7. throw t;
  8. }
  9. }
  10. };

代码示例来源:origin: Unidata/thredds

  1. public void write() throws IOException {
  2. try (RandomAccessFile raf = RandomAccessFile.acquire(fileIn)) {
  3. Grib2RecordScanner scanner = new Grib2RecordScanner(raf);
  4. while (scanner.hasNext()) {
  5. Grib2Record gr = scanner.next();
  6. float[] data = gr.readData(raf);
  7. for (int i=0; i<data.length; i++) {
  8. data[i] = bitShave(data[i], mask11);
  9. if (i % 10 == 0)
  10. System.out.println();
  11. }
  12. }
  13. }
  14. }

代码示例来源:origin: Unidata/thredds

  1. GribCollectionImmutable result = null;
  2. try (RandomAccessFile raf = RandomAccessFile.acquire(indexFilenameInCache)) {
  3. GribCollectionType type = getType(raf);

代码示例来源:origin: Unidata/thredds

  1. GribCollectionMutable result = null;
  2. try (RandomAccessFile raf = RandomAccessFile.acquire(indexFilenameInCache)) {
  3. GribCollectionType type = getType(raf);

代码示例来源:origin: Unidata/thredds

  1. @Override
  2. public boolean readMFiles(Path indexFile, List<MFile> result) throws IOException {
  3. if (debug) System.out.printf("GribCdmIndex.readMFiles %s%n", indexFile);
  4. try (RandomAccessFile raf = RandomAccessFile.acquire(indexFile.toString())) {
  5. // GribCollectionType type = getType(raf);
  6. // if (type == GribCollectionType.GRIB1 || type == GribCollectionType.GRIB2) {
  7. if (openIndex(raf, logger)) {
  8. File protoDir = new File(gribCollectionIndex.getTopDir());
  9. int n = gribCollectionIndex.getMfilesCount();
  10. for (int i = 0; i < n; i++) {
  11. GribCollectionProto.MFile mfilep = gribCollectionIndex.getMfiles(i);
  12. result.add(new GcMFile(protoDir, mfilep.getFilename(), mfilep.getLastModified(), mfilep.getLength(), mfilep.getIndex()));
  13. }
  14. }
  15. return true;
  16. //}
  17. }
  18. //return false;
  19. }

代码示例来源:origin: Unidata/thredds

  1. /**
  2. * Get the data file to use (if this is a template)
  3. *
  4. * @param eIndex ensemble index
  5. * @param tIndex time index
  6. * @return the current file
  7. * @throws IOException couldn't open the current file
  8. */
  9. private RandomAccessFile getDataFile(int eIndex, int tIndex) throws IOException {
  10. String dataFilePath = gradsDDF.getFileName(eIndex, tIndex);
  11. if (!gradsDDF.isTemplate()) { // we only have one file
  12. if (dataFile != null) {
  13. return dataFile;
  14. }
  15. }
  16. if (dataFile != null) {
  17. String path = dataFile.getLocation();
  18. if (path.equals(dataFilePath)) {
  19. return dataFile;
  20. } else {
  21. dataFile.close();
  22. }
  23. }
  24. dataFile = RandomAccessFile.acquire(dataFilePath);
  25. dataFile.order(getByteOrder());
  26. return dataFile;
  27. }
  28. }

代码示例来源:origin: Unidata/thredds

  1. @Override
  2. public boolean readChildren(Path indexFile, AddChildCallback callback) throws IOException {
  3. if (debug) System.out.printf("GribCdmIndex.readChildren %s%n", indexFile);
  4. try (RandomAccessFile raf = RandomAccessFile.acquire(indexFile.toString())) {
  5. GribCollectionType type = getType(raf);
  6. if (type == GribCollectionType.Partition1 || type == GribCollectionType.Partition2) {
  7. if (openIndex(raf, logger)) {
  8. String topDir = gribCollectionIndex.getTopDir();
  9. int n = gribCollectionIndex.getMfilesCount(); // partition index files stored in MFiles
  10. for (int i = 0; i < n; i++) {
  11. GribCollectionProto.MFile mfilep = gribCollectionIndex.getMfiles(i);
  12. callback.addChild(topDir, mfilep.getFilename(), mfilep.getLastModified());
  13. }
  14. return true;
  15. }
  16. }
  17. return false;
  18. }
  19. }

代码示例来源:origin: Unidata/thredds

  1. @Test
  2. public void testCheckFileType()
  3. throws Exception
  4. {
  5. String location = canonjoin(tdsContentRootPath, canonjoin(PREFIX, filename));
  6. try (RandomAccessFile raf = RandomAccessFile.acquire(location)) {
  7. // Verify type
  8. int found = NCheader.checkFileType(raf);
  9. String foundname = NCheader.formatName(found);
  10. String kindname = NCheader.formatName(kind);
  11. System.err.println("Testing format: " + kindname);
  12. Assert.assertTrue(String.format("***Fail: expected=%s found=%s%n", kindname, foundname),
  13. kind == found);
  14. }
  15. }

代码示例来源:origin: Unidata/thredds

  1. @Test
  2. public void testReadSubsection()
  3. throws IOException, InvalidRangeException
  4. {
  5. String location = canonjoin(tdsContentRootPath,"thredds/public/testdata/nc_test_cdf5.nc");
  6. try (RandomAccessFile raf = RandomAccessFile.acquire(location)) {
  7. // Verify that this is a netcdf-5 file
  8. int format = NCheader.checkFileType(raf);
  9. Assert.assertTrue("Fail: file format is not CDF-5",format == NCheader.NC_FORMAT_64BIT_DATA);
  10. }
  11. try (NetcdfFile jni = openJni(location)) {
  12. jni.setLocation(location + " (jni)");
  13. Array data = read(jni, "f4", "0:2");
  14. if(prop_visual) {
  15. String dump = NCdumpW.toString(data);
  16. logger.debug(dump);
  17. String testresult = dump.replace('r', ' ').replace('\n', ' ').trim();
  18. visual("CDF Read", testresult);
  19. }
  20. Assert.assertTrue(String.format("***Fail: data mismatch"),
  21. MAMath.nearlyEquals(data, BASELINE));
  22. System.err.println("***Pass");
  23. }
  24. }

代码示例来源:origin: Unidata/thredds

  1. byte[] b = new byte[recordsLen];
  2. try (RandomAccessFile indexRaf = RandomAccessFile.acquire(indexFilename)) {

相关文章