@Test public void testLocateStartOfEocd_WithFile_NoEocd() throws IOException { File tempFile = File.createTempFile("MinimalZipParserTest", "zip"); tempFile.deleteOnExit(); try { FileOutputStream out = new FileOutputStream(tempFile); out.write(new byte[4000]); out.flush(); out.close(); } catch (IOException e) { try { tempFile.delete(); } catch (Exception ignored) { } throw e; } try (RandomAccessFileInputStream in = new RandomAccessFileInputStream(tempFile)) { long eocdOffset = MinimalZipParser.locateStartOfEocd(in, 4000); Assert.assertEquals(-1, eocdOffset); } }
public static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength) throws IOException { final int maxBufferSize = (int) Math.min(searchBufferLength, in.length()); final byte[] buffer = new byte[maxBufferSize]; final long rangeStart = in.length() - buffer.length; in.setRange(rangeStart, buffer.length); readOrDie(in, buffer, 0, buffer.length); int offset = locateStartOfEocd(buffer); if (offset == -1) { return -1; } return rangeStart + offset; }
MinimalZipParser { public static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength) throws IOException { final int maxBufferSize = (int) Math.min(searchBufferLength, in.length()); final byte[] buffer = new byte[maxBufferSize]; final long rangeStart = in.length() - buffer.length; in.setRange(rangeStart, buffer.length); readOrDie(in, buffer, 0, buffer.length); int offset = locateStartOfEocd(buffer); if (offset == -1) { return -1; } return rangeStart + offset; } }
MinimalZipParser { public static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength) throws IOException { final int maxBufferSize = (int) Math.min(searchBufferLength, in.length()); final byte[] buffer = new byte[maxBufferSize]; final long rangeStart = in.length() - buffer.length; in.setRange(rangeStart, buffer.length); readOrDie(in, buffer, 0, buffer.length); int offset = locateStartOfEocd(buffer); if (offset == -1) { return -1; } return rangeStart + offset; }  }
MinimalZipParser { public static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength) throws IOException { final int maxBufferSize = (int) Math.min(searchBufferLength, in.length()); final byte[] buffer = new byte[maxBufferSize]; final long rangeStart = in.length() - buffer.length; in.setRange(rangeStart, buffer.length); readOrDie(in, buffer, 0, buffer.length); int offset = locateStartOfEocd(buffer); if (offset == -1) { return -1; } return rangeStart + offset; }  static MinimalZipEntry parseCentralDirectoryEntry(InputStream in); static long parseLocalEntryAndGetCompressedDataOffset(InputStream in); static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength); static int locateStartOfEocd(byte[] buffer); static MinimalCentralDirectoryMetadata parseEocd(InputStream in); }
MinimalZipParser { public static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength) throws IOException { final int maxBufferSize = (int) Math.min(searchBufferLength, in.length()); final byte[] buffer = new byte[maxBufferSize]; final long rangeStart = in.length() - buffer.length; in.setRange(rangeStart, buffer.length); readOrDie(in, buffer, 0, buffer.length); int offset = locateStartOfEocd(buffer); if (offset == -1) { return -1; } return rangeStart + offset; }  static MinimalZipEntry parseCentralDirectoryEntry(InputStream in); static long parseLocalEntryAndGetCompressedDataOffset(InputStream in); static long locateStartOfEocd(RandomAccessFileInputStream in, int searchBufferLength); static int locateStartOfEocd(byte[] buffer); static MinimalCentralDirectoryMetadata parseEocd(InputStream in); static final int EOCD_SIGNATURE; static final int CENTRAL_DIRECTORY_ENTRY_SIGNATURE; static final int LOCAL_ENTRY_SIGNATURE; }