@Test public void testStore() throws Exception { InputStream data = ByteStreams.newInputStreamSupplier("hejsan vad bra".getBytes()).getInput(); String path = Joiner.on(File.separatorChar) .join("com", "bygg", "bygg-test-artifact", "2.3", "bygg-test-artifact-2.3.jar"); File expectedFile = new File(repositoryDirectory, path); expectedFile.delete(); assertFalse(expectedFile.exists()); URL actualURl = repository.store(new ArtifactVersion(ARTIFACT, "2.3"), data); assertThat( actualURl, equalTo( new URL( "file:" + repositoryDirectory.getAbsolutePath() + "/com/bygg/bygg-test-artifact/2.3/bygg-test-artifact-2.3.jar"))); assertTrue(expectedFile.exists()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteStreams.copy(new FileInputStream(expectedFile), outputStream); assertThat(outputStream.toString(), equalTo("hejsan vad bra")); }
@Override public InputStream getInput(String relPath) { try { return ByteStreams.newInputStreamSupplier(data.get(relPath)).getInput(); } catch (Exception e) { return null; } }
private Set<String> zipEntries(final byte[] zipContent) throws IOException { final Set<String> entries = new HashSet<String>(); final ByteArrayInputStream inputStream = ByteStreams.newInputStreamSupplier(zipContent).getInput(); try (final ZipInputStream stream = new ZipInputStream(inputStream)) { ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { entries.add(entry.getName()); } } return entries; }
/** * Get the MD5 hash of the given stream. * * @param fis the input stream to use * @return a byte array of the MD5 hash * @throws java.security.NoSuchAlgorithmException if MD5 is not available * @throws IOException if an I/O error occurs */ private static byte[] md5(InputStream fis) throws NoSuchAlgorithmException, IOException { return ByteStreams.hash( ByteStreams.newInputStreamSupplier(ByteStreams.toByteArray(fis)), Hashing.md5()) .asBytes(); }