private static RandomAccessInputStream openStream(String file) throws IOException { return new RandomAccessInputStream(getHandle(file), file); }
/** * Constructs a new ZipHandle corresponding to the given entry of the * specified Zip file. * * @throws HandleException if the given file is not a Zip file. */ public ZipHandle(String file, ZipEntry entry) throws IOException { super(); this.file = file; in = openStream(file); zip = new ZipInputStream(in); entryName = entry.getName(); entryCount = 1; seekToEntry(); resetStream(); length = entry.getSize(); if (length <= 0) { populateLength(); } }
@Override protected void resetStream() throws IOException { if (stream != null) stream.close(); if (in != null) { in.close(); in = openStream(file); } if (zip != null) zip.close(); zip = new ZipInputStream(in); if (entryName != null) seekToEntry(); stream = new DataInputStream(new BufferedInputStream( zip, RandomAccessInputStream.MAX_OVERHEAD)); stream.mark(RandomAccessInputStream.MAX_OVERHEAD); }
this.file = file; in = openStream(file); zip = new ZipInputStream(in); entryName = null; length += ze.getSize(); resetStream(); populateLength();
ZipHandle handle = new ZipHandle(id, ze); Location.mapFile(ze.getName(), handle); mappedFiles.add(ze.getName());
private void populateLength() throws IOException { length = -1; while (stream.available() > 0) { stream.skip(1); length++; } resetStream(); }
this.file = file; in = openStream(file); zip = new ZipInputStream(in); entryName = null; length += ze.getSize(); resetStream(); populateLength();
@Override protected void resetStream() throws IOException { if (stream != null) stream.close(); if (in != null) { in.close(); in = openStream(file); } if (zip != null) zip.close(); zip = new ZipInputStream(in); if (entryName != null) seekToEntry(); stream = new DataInputStream(new BufferedInputStream( zip, RandomAccessInputStream.MAX_OVERHEAD)); stream.mark(RandomAccessInputStream.MAX_OVERHEAD); }
ZipHandle handle = new ZipHandle(id, ze); Location.mapFile(ze.getName(), handle); mappedFiles.add(ze.getName());
private void populateLength() throws IOException { length = -1; while (stream.available() > 0) { stream.skip(1); length++; } resetStream(); }
/** * Constructs a new ZipHandle corresponding to the given entry of the * specified Zip file. * * @param file a name that can be passed to * {@link Location#getHandle(String, boolean, boolean)} * @param entry the specific entry in the Zip file to be opened * @throws HandleException if the given file is not a Zip file. * @see ZipEntry */ public ZipHandle(String file, ZipEntry entry) throws IOException { super(); this.file = file; in = openStream(file); zip = new ZipInputStream(in); entryName = entry.getName(); entryCount = 1; seekToEntry(); resetStream(); length = entry.getSize(); if (length <= 0) { populateLength(); } }
private static RandomAccessInputStream openStream(String file) throws IOException { return new RandomAccessInputStream(getHandle(file), file); }
/** 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"); }