/** * Create a new, uniquely named file in the root directory. * Mimics File.createTempFile() * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @return uniquely named file */ public synchronized File createUniqueFile(String prefix, String suffix) { if (suffix == null) suffix = ".tmp"; Random random = new Random(System.currentTimeMillis()); File result = new File(getRootDirectory(), prefix + Integer.toString(random.nextInt()) + suffix); while (result.exists()) result = new File(getRootDirectory(), prefix + Integer.toString(random.nextInt()) + suffix); return result; }
/** * Create a new, uniquely named file in the root directory. * Mimics File.createTempFile() * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @return uniquely named file */ public synchronized File createUniqueFile(String prefix, String suffix) { if (suffix == null) suffix = ".tmp"; Random random = new Random(System.currentTimeMillis()); File result = new File(getRootDirectory(), prefix + Integer.toString(random.nextInt()) + suffix); while (result.exists()) result = new File(getRootDirectory(), prefix + Integer.toString(random.nextInt()) + suffix); return result; }
/** * Create a new, uniquely named file in the root directory. * Mimics File.createTempFile() * * @param prefix The prefix string to be used in generating the file's * name; must be at least three characters long * @param suffix The suffix string to be used in generating the file's * name; may be <code>null</code>, in which case the * suffix <code>".tmp"</code> will be used * @return uniquely named file */ public synchronized File createUniqueFile(String prefix, String suffix) { if (suffix == null) suffix = ".tmp"; Random random = new Random(System.currentTimeMillis()); File result = new File(getRootDirectory(), prefix + Integer.toString(random.nextInt()) + suffix); while (result.exists()) result = new File(getRootDirectory(), prefix + Integer.toString(random.nextInt()) + suffix); return result; }
public static FmrcInventory makeFromCatalog(DiskCache2 cache, String catURL, String collectionName, int maxDatasets, int mode) throws Exception { String fmrcDefinitionPath = (cache == null)? null : cache.getRootDirectory()+"/defs/"; System.out.println("***makeFromCatalog "+catURL); long startTime = System.currentTimeMillis(); FmrcInventory fmrCollection = new FmrcInventory(fmrcDefinitionPath, collectionName); CatalogCrawler crawler = new CatalogCrawler(CatalogCrawler.USE_ALL_DIRECT, false, new MyListener(fmrCollection, maxDatasets, mode, cache)); crawler.crawl(catURL, null, System.out, null); fmrCollection.finish(); if (debugTiming) { long took = System.currentTimeMillis() - startTime; System.out.println("that took = "+took+" msecs"); } return fmrCollection; }
/** debug */ static public void main(String[] args) throws IOException { DiskCache2 dc = new DiskCache2("C:/TEMP/test/", false, 0, 0); dc.setRootDirectory("C:/temp/chill/"); make(dc, "C:/junk.txt"); make(dc, "C:/some/enchanted/evening/joots+3478.txt"); make(dc, "http://www.unidata.ucar.edu/some/enc hanted/eve'ning/nowrite.gibberish"); dc.showCache( System.out); StringBuilder sbuff = new StringBuilder(); dc.cleanCache(new File( dc.getRootDirectory()), sbuff, true); System.out.println(sbuff); }
public File writeCoverageDataToFile() throws WcsException { try { File dir = new File( getDiskCache().getRootDirectory() ); File ncFile = File.createTempFile( "WCS", ".nc", dir ); NetcdfCFWriter writer = new NetcdfCFWriter(); writer.makeFile( ncFile.getPath(), dataset, Collections.singletonList( identifier ), null, null, // Collections.singletonList( req.getCoverage() ), // req.getBoundingBox(), dateRange, true, 1, 1, 1 ); return ncFile; } catch ( InvalidRangeException e ) { log.error( "writeCoverageDataToFile(): Failed to subset coverage <" + identifier + ">: " + e.getMessage()); throw new WcsException( WcsException.Code.UnsupportedCombination, "", "Failed to subset coverage <" + identifier + ">."); } catch ( IOException e ) { log.error( "writeCoverageDataToFile(): Failed to write file for requested coverage <" + identifier + ">: " + e.getMessage()); throw new WcsException( WcsException.Code.NoApplicableCode, "", "Problem creating coverage <" + identifier + ">." ); } }
DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0); cache.setAlwaysUseCache(true); Assert.assertEquals(cache.getRootDirectory(), cacheDirName); assert new File(cache.getRootDirectory()).exists(); GribIndexCache.setDiskCache2(cache);
File dir = new File( getDiskCache().getRootDirectory() ); File tifFile = File.createTempFile( "WCS", ".tif", dir ); if ( log.isDebugEnabled() ) File dir = new File( getDiskCache().getRootDirectory() ); File ncFile = File.createTempFile( "WCS", ".nc", dir ); if ( log.isDebugEnabled() )
Assert.assertEquals(cache.getRootDirectory(), cacheDirName); assert new File(cache.getRootDirectory()).exists();
@Test public void testCacheIsUsed() throws IOException, InvalidRangeException { String filename = "file:TestAggExistingCache.xml"; System.out.printf("%s%n", filename); String cacheDirName = tempFolder.newFolder().getAbsolutePath() + "/"; System.out.printf("cacheDir=%s%n", cacheDirName); File cacheDir = new File(cacheDirName); FileUtils.deleteDirectory(cacheDir); // from commons-io assert !cacheDir.exists(); DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0); cache.setAlwaysUseCache(true); Assert.assertEquals(cache.getRootDirectory(), cacheDirName); assert new File(cache.getRootDirectory()).exists(); Aggregation.setPersistenceCache(cache); AggregationExisting.countCacheUse = 0; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) { System.out.println(" TestNcmlAggExisting.open " + filename); Array ATssta = ncfile.readSection("ATssta(:,0,0,0)"); Assert.assertEquals(4, ATssta.getSize()); } Assert.assertEquals(0, AggregationExisting.countCacheUse); AggregationExisting.countCacheUse = 0; try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) { System.out.println(" TestNcmlAggExisting.open " + filename); Array ATssta = ncfile.readSection("ATssta(:,0,0,0)"); Assert.assertEquals(4, ATssta.getSize()); } Assert.assertEquals(8, AggregationExisting.countCacheUse); }
File dir = new File( getDiskCache().getRootDirectory() ); File tifFile = File.createTempFile( "WCS", ".tif", dir ); if ( log.isDebugEnabled() ) File dir = new File( getDiskCache().getRootDirectory() ); File ncFile = File.createTempFile( "WCS", ".nc", dir ); if ( log.isDebugEnabled() )