private byte[] loadResource(String resourceName) { try (InputStream resourceAsStream = DebugHttpServer.class.getResourceAsStream(resourceName)) { if (resourceAsStream != null) { return StreamUtil.read(resourceAsStream); } else { throw new RuntimeException( "Failed to find resource " + resourceName + " for debug http exporter"); } } catch (IOException e) { throw new RuntimeException( "Failed to read resource " + resourceName + " for debug http exporter", e); } }
public static void write( final File file, final InputStream data, final MessageDigest messageDigest) throws IOException { try (DigestOutputStream os = new DigestOutputStream(new FileOutputStream(file), messageDigest)) { copy(data, os); } final String digest = digestAsHex(messageDigest); final String fileName = file.getName(); final String content = String.format("%s %s", digest, fileName); final String algorithm = messageDigest.getAlgorithm().toLowerCase(); final String targetFileName = String.format("%s.%s", file.getAbsolutePath(), algorithm); write(new File(targetFileName), content); }
public static MessageDigest getSha1Digest() { return getDigest("SHA1"); }
public static String sha1Hex(final InputStream data) throws IOException { final MessageDigest messageDigest = updateDigest(getSha1Digest(), data); return digestAsHex(messageDigest); }
public static boolean canRead(final File file, final MessageDigest messageDigest) { boolean isReadable = false; final File checksum = new File(file.getAbsolutePath() + "." + messageDigest.getAlgorithm().toLowerCase()); if (file.exists() && checksum.exists()) { String checksumDigest = null; String checksumFileName = null; try (InputStream is = new FileInputStream(checksum)) { final byte[] data = new byte[(int) checksum.length()]; read(is, data); final String content = fromBytes(data); final String[] parts = content.split(" "); checksumDigest = parts[0]; checksumFileName = parts[1]; } catch (final IOException e) { // ignore } if (checksumFileName.equals(file.getName())) { try (InputStream is = new FileInputStream(file)) { updateDigest(messageDigest, is); } catch (final IOException e) { // ignore } final String digest = digestAsHex(messageDigest); isReadable = digest.equals(checksumDigest); } } return isReadable; }
@Override public long writeSnapshot(OutputStream outputStream) throws Exception { StreamUtil.write(indexBuffer, outputStream); return indexBuffer.capacity(); }
public static boolean canRead(final File file, final MessageDigest messageDigest) { boolean isReadable = false; final File checksum = new File(file.getAbsolutePath() + "." + messageDigest.getAlgorithm().toLowerCase()); if (file.exists() && checksum.exists()) { String checksumDigest = null; String checksumFileName = null; try (InputStream is = new FileInputStream(checksum)) { final byte[] data = new byte[(int) checksum.length()]; read(is, data); final String content = fromBytes(data); final String[] parts = content.split(" "); checksumDigest = parts[0]; checksumFileName = parts[1]; } catch (final IOException e) { // ignore } if (checksumFileName.equals(file.getName())) { try (InputStream is = new FileInputStream(file)) { updateDigest(messageDigest, is); } catch (final IOException e) { // ignore } final String digest = digestAsHex(messageDigest); isReadable = digest.equals(checksumDigest); } } return isReadable; }
public static String sha1Hex(final InputStream data) throws IOException { final MessageDigest messageDigest = updateDigest(getSha1Digest(), data); return digestAsHex(messageDigest); }
/** * Writes the {@link DirectBuffer#capacity} bytes given buffer to the destination output. * * @param source buffer to write * @param destination output to write to * @throws IOException */ public static void write(final DirectBuffer source, final OutputStream destination) throws IOException { write(source, destination, 0, source.capacity()); }
private byte[] loadResource(String resourceName) { try (InputStream resourceAsStream = DebugHttpServer.class.getResourceAsStream(resourceName)) { if (resourceAsStream != null) { return StreamUtil.read(resourceAsStream); } else { throw new RuntimeException( "Failed to find resource " + resourceName + " for debug http exporter"); } } catch (IOException e) { throw new RuntimeException( "Failed to read resource " + resourceName + " for debug http exporter", e); } }
public static void write( final File file, final InputStream data, final MessageDigest messageDigest) throws IOException { try (DigestOutputStream os = new DigestOutputStream(new FileOutputStream(file), messageDigest)) { copy(data, os); } final String digest = digestAsHex(messageDigest); final String fileName = file.getName(); final String content = String.format("%s %s", digest, fileName); final String algorithm = messageDigest.getAlgorithm().toLowerCase(); final String targetFileName = String.format("%s.%s", file.getAbsolutePath(), algorithm); write(new File(targetFileName), content); }
/** * Writes the {@link DirectBuffer#capacity} bytes given buffer to the destination output. * * @param source buffer to write * @param destination output to write to * @throws IOException */ public static void write(final DirectBuffer source, final OutputStream destination) throws IOException { write(source, destination, 0, source.capacity()); }
public static MessageDigest getSha1Digest() { return getDigest("SHA1"); }
@Override public void recoverFromSnapshot(InputStream inputStream) throws Exception { final byte[] byteArray = StreamUtil.read(inputStream); indexBuffer.putBytes(0, byteArray); }
@Override public long writeSnapshot(OutputStream outputStream) throws Exception { StreamUtil.write(indexBuffer, outputStream); return indexBuffer.capacity(); }
@Override public void recoverFromSnapshot(InputStream inputStream) throws Exception { final byte[] byteArray = StreamUtil.read(inputStream); indexBuffer.putBytes(0, byteArray); }
@Override public DeployWorkflowCommandBuilderStep2 addResourceStream( final InputStream resourceStream, final String resourceName) { ensureNotNull("resource stream", resourceStream); try { final byte[] bytes = StreamUtil.read(resourceStream); return addResourceBytes(bytes, resourceName); } catch (final IOException e) { final String exceptionMsg = String.format("Cannot deploy bpmn resource from stream. %s", e.getMessage()); throw new ClientException(exceptionMsg, e); } }
@Override public DeployWorkflowCommandBuilderStep2 addResourceStream( final InputStream resourceStream, final String resourceName) { ensureNotNull("resource stream", resourceStream); try { final byte[] bytes = StreamUtil.read(resourceStream); return addResourceBytes(bytes, resourceName); } catch (final IOException e) { final String exceptionMsg = String.format("Cannot deploy bpmn resource from stream. %s", e.getMessage()); throw new ClientException(exceptionMsg, e); } }
public static int read( final InputStream input, final MutableDirectBuffer buffer, final int offset) throws IOException { int bytesRead; if (buffer.byteArray() == null) { throw new RuntimeException("Cannot be used with direct byte buffers"); } int writeOffset = offset; do { buffer.checkLimit( offset + DEFAULT_BUFFER_SIZE); // for expandable buffers, this triggers expansion bytesRead = input.read(buffer.byteArray(), writeOffset, DEFAULT_BUFFER_SIZE); if (bytesRead > 0) { writeOffset += bytesRead; } } while (bytesRead >= 0); return writeOffset - offset; }
public static int read( final InputStream input, final MutableDirectBuffer buffer, final int offset) throws IOException { int bytesRead; if (buffer.byteArray() == null) { throw new RuntimeException("Cannot be used with direct byte buffers"); } int writeOffset = offset; do { buffer.checkLimit( offset + DEFAULT_BUFFER_SIZE); // for expandable buffers, this triggers expansion bytesRead = input.read(buffer.byteArray(), writeOffset, DEFAULT_BUFFER_SIZE); if (bytesRead > 0) { writeOffset += bytesRead; } } while (bytesRead >= 0); return writeOffset - offset; }