@Override public long getFilePointer() throws IOException { ensureOpen(); return filePointer; }
/** * {@inheritDoc} */ @Override public void handle(IdentificationRequest request) throws IOException { final ZipFile zipFile = new ZipFile(new ReaderReadOnlyFile(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 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 (offset + length > bytes.length) { throw new IndexOutOfBoundsException("The offset " + offset + " plus length " + length + " cannot be greater than the length of the bytes " + bytes.length); } if (filePointer >= length() || length == 0) { return -1; } final int bytesToRead = length - offset; int totalRead = 0; Window window = reader.getWindow(filePointer); while (window != null && totalRead < bytesToRead) { final int windowOffset = reader.getWindowOffset(filePointer); final int availableBytes = window.length() - windowOffset; final int remainingBytes = length - totalRead; final int copyBytes = remainingBytes < availableBytes ? remainingBytes : availableBytes; System.arraycopy(window.getArray(), windowOffset, bytes, offset + totalRead, copyBytes); totalRead += copyBytes; filePointer += copyBytes; window = reader.getWindow(filePointer); } return totalRead; }
@Override public void process(IdentificationRequest request, ContainerSignatureMatchCollection matches) throws IOException { ZipFile zipFile = new ZipFile(new ReaderReadOnlyFile(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; }