ASiCUtils { public static boolean isZip(DSSDocument dssDocument) { if (dssDocument == null) { return false; } byte[] preamble = new byte[2]; try (InputStream is = dssDocument.openStream()) { int r = is.read(preamble, 0, 2); if (r != 2) { return false; } } catch (IOException e) { throw new DSSException("Unable to read the 2 first bytes", e); } return (preamble[0] == 'P') && (preamble[1] == 'K'); } private  ASiCUtils(); static boolean isSignature(final String entryName); static boolean isTimestamp(final String entryName); static String getMimeTypeString(final ASiCParameters asicParameters); static boolean isASiCMimeType(final MimeType asicMimeType); static boolean isOpenDocumentMimeType(final MimeType mimeType); static ASiCContainerType getASiCContainerType(final MimeType asicMimeType); static boolean isASiCE(final ASiCParameters asicParameters); static boolean isASiCS(final ASiCParameters asicParameters); static MimeType getMimeType(ASiCParameters asicParameters); static boolean isArchiveContainsCorrectSignatureFileWithExtension(DSSDocument container, String extension); static boolean isArchiveContainsCorrectTimestamp(DSSDocument container); static boolean isArchive(List<DSSDocument> docs); static boolean isZip(DSSDocument dssDocument); static boolean isASiCWithCAdES(DSSDocument archive); static boolean isXAdES(final String entryName); static boolean isCAdES(final String entryName); static boolean isOpenDocument(final DSSDocument mimeTypeDoc); static MimeType getMimeType(final DSSDocument mimeTypeDocument); static ASiCContainerType getContainerType(DSSDocument archive, DSSDocument mimetype, String zipComment, List<DSSDocument> signedDocuments); static String getPadNumber(int num); static boolean isAsic(List<DSSDocument> documents); static boolean isArchiveManifest(String fileName); static void secureCopy(InputStream is, OutputStream os, long containerSize); static List<String> getFileNames(DSSDocument archive); static ZipEntry getNextValidEntry(ZipInputStream zis); static DSSDocument getCurrentDocument(String filepath, ZipInputStream zis, long containerSize); static void closeEntry(ZipInputStream zis); static String getNextASiCEManifestName(final String expectedManifestName, final List<DSSDocument> existingManifests); static List<String> getDSSDocumentNames(List<DSSDocument> documents); static boolean isASiCSArchive(DSSDocument document); static List<DSSDocument> getPackageZipContent(DSSDocument packageZip); static final String MANIFEST_FILENAME; static final String MIME_TYPE; static final String MIME_TYPE_COMMENT; static final String META_INF_FOLDER; static final String PACKAGE_ZIP; static final String SIGNATURE_FILENAME; static final String TIMESTAMP_FILENAME; static final String TST_EXTENSION; static final String XML_EXTENSION; static final String ZIP_ENTRY_DETACHED_FILE; }
@Test public void isZip() { assertFalse(ASiCUtils.isZip(null)); assertFalse(ASiCUtils.isZip(new InMemoryDocument(new byte[] { 0 }))); assertFalse(ASiCUtils.isZip(new InMemoryDocument(new byte[] { 'P', 'P' }))); assertFalse(ASiCUtils.isZip(new InMemoryDocument(new byte[] { 'p', 'k' }))); InMemoryDocument emptyInMemoryDoc = new InMemoryDocument(); assertThrows(NullPointerException.class, () -> ASiCUtils.isZip(emptyInMemoryDoc)); assertTrue(ASiCUtils.isZip(new InMemoryDocument(new byte[] { 'P', 'K' }))); }