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

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

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

RandomAccessFile.acquire介绍

暂无

代码示例

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

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

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

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

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

private void init() {
 if (!exists) return;
 try {
  if (dataRaf != null)
   this.timeSeriesRaf = dataRaf; // single station case - data file already open
  else
   this.timeSeriesRaf = RandomAccessFile.acquire(file.getPath());
  totalBytes = timeSeriesRaf.length();
  timeSeriesRaf.seek(0);
 } catch (IOException e) {
  throw new RuntimeException(e);
 }
}

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

public RandomAccessFile getDataRaf(int fileno) throws IOException {
 // absolute location
 MFile mfile = fileMap.get(fileno);
 String filename = mfile.getPath();
 File dataFile = new File(filename);
 // if data file does not exist, check reletive location - eg may be /upc/share instead of Q:
 if (!dataFile.exists()) {
  if (fileMap.size() == 1) {
   dataFile = new File(directory, name); // single file case
  } else {
   dataFile = new File(directory, dataFile.getName()); // must be in same directory as the ncx file
  }
 }
 // data file not here
 if (!dataFile.exists()) {
  throw new FileNotFoundException("data file not found = " + dataFile.getPath());
 }
 RandomAccessFile want = RandomAccessFile.acquire(dataFile.getPath());
 want.order(RandomAccessFile.BIG_ENDIAN);
 return want;
}

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

public static BufrCdmIndex readIndex(String indexFilename) throws IOException {
 BufrCdmIndex index =  new BufrCdmIndex();
 try (RandomAccessFile raf = RandomAccessFile.acquire(indexFilename)) {
   index.readIndex(raf);
 }
 return index;
}

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

static private boolean isUpdateNeeded(String idxFilenameOrg, CollectionUpdateType updateType, GribCollectionType wantType, Logger logger) {
 if (updateType == CollectionUpdateType.never) return false;
 // see if index already exists
 File collectionIndexFile = GribIndexCache.getExistingFileOrCache(idxFilenameOrg);
 if (collectionIndexFile != null) {   // it exists
  boolean bad;
  try (RandomAccessFile raf = RandomAccessFile.acquire(collectionIndexFile.getPath())) {  // read it to verify its good
   GribCollectionType type = getType(raf);
   bad = (type != wantType);
   if (!bad && updateType == CollectionUpdateType.nocheck) return false;  // use if index is ok
  } catch (IOException ioe) {
   bad = true;
  }
  if (bad) { // delete the file and remove from cache if its in there
   RandomAccessFile.eject(collectionIndexFile.getPath());
   if (!collectionIndexFile.delete())
    logger.warn("failed to delete {}", collectionIndexFile.getPath());
  }
 }
 return true;
}

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

dataRaf = RandomAccessFile.acquire(base+DAT_EXT);
stnRaf = RandomAccessFile.acquire(base+STN_EXT);
stnRaf = RandomAccessFile.acquire(base+STN_EXT);
dataRaf = RandomAccessFile.acquire(base+DAT_EXT);

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

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

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

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

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

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

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

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

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

public void write() throws IOException {
 try (RandomAccessFile raf = RandomAccessFile.acquire(fileIn)) {
  Grib2RecordScanner scanner = new Grib2RecordScanner(raf);
  while (scanner.hasNext()) {
   Grib2Record gr = scanner.next();
   float[] data = gr.readData(raf);
   for (int i=0; i<data.length; i++) {
    data[i] = bitShave(data[i], mask11);
    if (i % 10 == 0)
     System.out.println();
   }
  }
 }
}

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

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

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

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

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

@Override
public boolean readMFiles(Path indexFile, List<MFile> result) throws IOException {
 if (debug) System.out.printf("GribCdmIndex.readMFiles %s%n", indexFile);
 try (RandomAccessFile raf = RandomAccessFile.acquire(indexFile.toString())) {
  // GribCollectionType type = getType(raf);
  // if (type == GribCollectionType.GRIB1 || type == GribCollectionType.GRIB2) {
  if (openIndex(raf, logger)) {
   File protoDir = new File(gribCollectionIndex.getTopDir());
   int n = gribCollectionIndex.getMfilesCount();
   for (int i = 0; i < n; i++) {
    GribCollectionProto.MFile mfilep = gribCollectionIndex.getMfiles(i);
    result.add(new GcMFile(protoDir, mfilep.getFilename(), mfilep.getLastModified(), mfilep.getLength(), mfilep.getIndex()));
   }
  }
  return true;
  //}
 }
 //return false;
}

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

/**
  * Get the data file to use (if this is a template)
  *
  * @param eIndex ensemble index
  * @param tIndex time index
  * @return the current file
  * @throws IOException couldn't open the current file
  */
 private RandomAccessFile getDataFile(int eIndex, int tIndex) throws IOException {

  String dataFilePath = gradsDDF.getFileName(eIndex, tIndex);
  if (!gradsDDF.isTemplate()) {  // we only have one file
   if (dataFile != null) {
    return dataFile;
   }
  }
  if (dataFile != null) {
   String path = dataFile.getLocation();
   if (path.equals(dataFilePath)) {
    return dataFile;
   } else {
    dataFile.close();
   }
  }
  dataFile = RandomAccessFile.acquire(dataFilePath);
  dataFile.order(getByteOrder());
  return dataFile;
 }
}

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

@Override
public boolean readChildren(Path indexFile, AddChildCallback callback) throws IOException {
 if (debug) System.out.printf("GribCdmIndex.readChildren %s%n", indexFile);
 try (RandomAccessFile raf = RandomAccessFile.acquire(indexFile.toString())) {
  GribCollectionType type = getType(raf);
  if (type == GribCollectionType.Partition1 || type == GribCollectionType.Partition2) {
   if (openIndex(raf, logger)) {
    String topDir = gribCollectionIndex.getTopDir();
    int n = gribCollectionIndex.getMfilesCount(); // partition index files stored in MFiles
    for (int i = 0; i < n; i++) {
     GribCollectionProto.MFile mfilep = gribCollectionIndex.getMfiles(i);
     callback.addChild(topDir, mfilep.getFilename(), mfilep.getLastModified());
    }
    return true;
   }
  }
  return false;
 }
}

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

@Test
public void testCheckFileType()
    throws Exception
{
  String location = canonjoin(tdsContentRootPath, canonjoin(PREFIX, filename));
  try (RandomAccessFile raf = RandomAccessFile.acquire(location)) {
    // Verify type
    int found = NCheader.checkFileType(raf);
    String foundname = NCheader.formatName(found);
    String kindname = NCheader.formatName(kind);
    System.err.println("Testing format: " + kindname);
    Assert.assertTrue(String.format("***Fail: expected=%s found=%s%n", kindname, foundname),
        kind == found);
  }
}

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

@Test
public void testReadSubsection()
    throws IOException, InvalidRangeException
{
  String location = canonjoin(tdsContentRootPath,"thredds/public/testdata/nc_test_cdf5.nc");
  try (RandomAccessFile raf  = RandomAccessFile.acquire(location)) {
    // Verify that this is a netcdf-5 file
    int format = NCheader.checkFileType(raf);
    Assert.assertTrue("Fail: file format is not CDF-5",format == NCheader.NC_FORMAT_64BIT_DATA);
  }
  try (NetcdfFile jni = openJni(location)) {
    jni.setLocation(location + " (jni)");
    Array data = read(jni, "f4", "0:2");
    if(prop_visual) {
      String dump = NCdumpW.toString(data);
      logger.debug(dump);
      String testresult = dump.replace('r', ' ').replace('\n', ' ').trim();
      visual("CDF Read", testresult);
    }
    Assert.assertTrue(String.format("***Fail: data mismatch"),
                     MAMath.nearlyEquals(data, BASELINE));
    System.err.println("***Pass");
  }
}

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

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

相关文章