/** Closes the streams. */ @Override public void close() throws IOException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("RandomAccessInputStream {} CLOSE", hashCode()); } if (Location.getMappedFile(file) != null) return; if (raf != null) raf.close(); raf = null; markedPos = -1; }
/** Closes the streams. */ @Override public void close() throws IOException { if (LOGGER.isTraceEnabled()) { LOGGER.trace("RandomAccessInputStream {} CLOSE", hashCode()); } if (Location.getMappedFile(file) != null) return; if (raf != null) raf.close(); raf = null; markedPos = -1; }
@Override public void close() throws IOException { flush(); outputFile.close(); }
@Override public void close() throws IOException { flush(); outputFile.close(); }
/** Returns true if the given filename is a Zip file. */ public static boolean isZipFile(String file) throws IOException { if (!file.toLowerCase().endsWith(".zip")) return false; IRandomAccess handle = getHandle(file); byte[] b = new byte[2]; if (handle.length() >= 2) { handle.read(b); } handle.close(); return new String(b, Constants.ENCODING).equals("PK"); }
/** * @param file a name that can be passed to * {@link Location#getHandle(String, boolean, boolean)} * @return true if the given filename is a Zip file. * @throws IOException if the file cannot be read */ public static boolean isZipFile(String file) throws IOException { if (!file.toLowerCase().endsWith(".zip")) return false; IRandomAccess handle = getHandle(file); byte[] b = new byte[2]; if (handle.length() >= 2) { handle.read(b); } handle.close(); return new String(b, Constants.ENCODING).equals("PK"); }
/** * Checks that the given id points at a valid data stream. * * @param id * The id string to validate. * @throws IOException * if the id is not valid. */ public static void checkValidId(String id) throws IOException { if (getMappedFile(id) != null) { // NB: The id maps directly to an IRandomAccess handle, so is valid. Do // not destroy an existing mapped IRandomAccess handle by closing it. return; } // NB: Try to actually open a handle to make sure it is valid. Close it // afterward so we don't leave it dangling. The process of doing this will // throw IOException if something goes wrong. Location.getHandle(id).close(); }
/** * Checks that the given id points at a valid data stream. * * @param id * The id string to validate. * @throws IOException * if the id is not valid. */ public static void checkValidId(String id) throws IOException { if (getMappedFile(id) != null) { // NB: The id maps directly to an IRandomAccess handle, so is valid. Do // not destroy an existing mapped IRandomAccess handle by closing it. return; } // NB: Try to actually open a handle to make sure it is valid. Close it // afterward so we don't leave it dangling. The process of doing this will // throw IOException if something goes wrong. Location.getHandle(id).close(); }
@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; }
/** * Write a summary of each field in the IM3 file to the writer * @throws IOException */ public void writeSummary() throws IOException { IRandomAccess is = Location.getHandle(getCurrentFile(), false); try { is.setOrder(ByteOrder.LITTLE_ENDIAN); for (IM3Record rec: records) { rec.writeSummary(is, ""); } } finally { is.close(); } } /**
/** * Write a summary of each field in the IM3 file to the writer * @throws IOException */ public void writeSummary() throws IOException { IRandomAccess is = Location.getHandle(getCurrentFile(), false); try { is.setOrder(ByteOrder.LITTLE_ENDIAN); for (IM3Record rec: records) { rec.writeSummary(is, ""); } } finally { is.close(); } } /**