@Override public int read(byte[] bytes, int offset, int length) throws IOException { ensureOpen(); if ((offset | length) < 0) { throw new IndexOutOfBoundsException("Offset or length cannot be negative: {" + offset + "," + length + "}"); } if (filePointer >= length() || length == 0) { return -1; } final int bytesCopied = ArchiveFileUtils.copyToBuffer(reader, filePointer, bytes, offset, length); filePointer += bytesCopied; return bytesCopied; }
/** * {@inheritDoc} */ @Override public void handle(IdentificationRequest request) throws IOException { final ZipFile zipFile = new ZipFile(new TrueZipReader(request.getWindowReader())); try { Iterable<ZipEntry> iterable = new Iterable<ZipEntry>() { @Override public final Iterator<ZipEntry> iterator() { return new ZipFileIterator(zipFile); } }; ZipArchiveWalker walker = new ZipArchiveWalker(request.getIdentifier(), zipFile); walker.walk(iterable); } finally { if (zipFile != null) { zipFile.close(); } } }
@Override public long getFilePointer() throws IOException { ensureOpen(); return filePointer; }
@Override public void process(IdentificationRequest request, ContainerSignatureMatchCollection matches) throws IOException { ZipFile zipFile = new ZipFile(new TrueZipReader(request.getWindowReader()), ZipFile.DEFAULT_CHARSET, true, false); try {
@Override public int read() throws IOException { ensureOpen(); final int result = reader.readByte(filePointer); if (result >= 0) { filePointer++; } return result; }
@Override public void seek(long position) throws IOException { ensureOpen(); if (position < 0) { throw new IOException("Cannot seek to a negative position: " + position); } if (position >= reader.length()) { throw new IOException("Cannot seek past the end of data with length " + reader.length() + ". Seek position was " + position); } filePointer = position; }