@Override public void close(boolean fileOnly) throws IOException { super.close(fileOnly); if (!fileOnly) { stacks = null; sampleTable = null; stringTable = null; dir = null; timestamps.clear(); Location.mapFile(EMBEDDED_STREAM, null); } }
@Override public void close(boolean fileOnly) throws IOException { super.close(fileOnly); if (!fileOnly) { stacks = null; sampleTable = null; stringTable = null; dir = null; timestamps.clear(); Location.mapFile(EMBEDDED_STREAM, null); } }
/** * Map the given file into memory. * * @return true if the mapping was successful. */ public static boolean mapFile(String id) throws IOException { RandomAccessInputStream stream = new RandomAccessInputStream(id); Runtime rt = Runtime.getRuntime(); long maxMem = rt.freeMemory(); long length = stream.length(); if (length < Integer.MAX_VALUE && length < maxMem) { stream.close(); FileInputStream fis = new FileInputStream(id); FileChannel channel = fis.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); ByteArrayHandle handle = new ByteArrayHandle(buf); Location.mapFile(id, handle); fis.close(); return true; } stream.close(); return false; }
@Override public void close(boolean fileOnly) throws IOException { super.close(fileOnly); if (reader != null) reader.close(fileOnly); if (!fileOnly) reader = null; for (String name : mappedFiles) { IRandomAccess handle = Location.getMappedFile(name); Location.mapFile(name, null); if (handle != null) { handle.close(); } } mappedFiles.clear(); entryName = null; }
@Override public void close(boolean fileOnly) throws IOException { super.close(fileOnly); if (reader != null) reader.close(fileOnly); if (!fileOnly) reader = null; for (String name : mappedFiles) { IRandomAccess handle = Location.getMappedFile(name); Location.mapFile(name, null); if (handle != null) { handle.close(); } } mappedFiles.clear(); entryName = null; }
Location.mapFile(ze.getName(), handle); mappedFiles.add(ze.getName());
Location.mapFile(ze.getName(), handle); mappedFiles.add(ze.getName());
public void mapLocation() throws IOException { if (map != null) Location.mapId(id, map); else if (preload) { RandomAccessInputStream f = new RandomAccessInputStream(id); if (!(reader instanceof ImageReader)) { // verify format LOGGER.info("Checking {} format [{}]", reader.getFormat(), reader.isThisType(f) ? "yes" : "no"); f.seek(0); } int len = (int) f.length(); LOGGER.info("Caching {} bytes:", len); byte[] b = new byte[len]; int blockSize = 8 * 1024 * 1024; // 8 MB int read = 0, left = len; while (left > 0) { int r = f.read(b, read, blockSize < left ? blockSize : left); read += r; left -= r; float ratio = (float) read / len; int p = (int) (100 * ratio); LOGGER.info("\tRead {} bytes ({}% complete)", read, p); } f.close(); ByteArrayHandle file = new ByteArrayHandle(b); Location.mapFile(id, file); } }
@Test(dataProvider = "nonTiling") public void testSaveBytesInMemory(int tileSize, boolean littleEndian, boolean interleaved, int rgbChannels, int seriesCount, int sizeT, String compression, int pixelType, boolean bigTiff) throws Exception { if (percentageOfSaveBytesTests == 0) return; ByteArrayHandle handle = new ByteArrayHandle(); String id = Math.random() + "-" + System.currentTimeMillis() + ".tif"; Location.mapFile(id, handle); Plane originalPlane = WriterUtilities.writeImage(id, tileSize, littleEndian, interleaved, rgbChannels, seriesCount, sizeT, compression, pixelType, bigTiff); ByteBuffer bytes = handle.getByteBuffer(); byte[] file = new byte[(int) handle.length()]; bytes.position(0); bytes.get(file); handle = new ByteArrayHandle(file); Location.mapFile(id, handle); TiffReader reader = new TiffReader(); reader.setId(id); WriterUtilities.checkImage(reader, originalPlane, interleaved, rgbChannels, seriesCount, sizeT, compression); reader.close(); Location.mapFile(id, null); }
Location.mapFile(currentId + ".fixed", bytes); super.setId(currentId + ".fixed");
Location.mapFile(currentId + ".fixed", bytes); super.setId(currentId + ".fixed");
IRandomAccess data = new ByteArrayHandle((byte[]) sampleTable[row][13]); Location.mapFile(stack.pixelsFiles[0], data);
IRandomAccess data = new ByteArrayHandle((byte[]) sampleTable[row][13]); Location.mapFile(stack.pixelsFiles[0], data);