/** * Returns a factory that will supply instances of * {@link ByteArrayInputStream} that read from the given byte array. * * @param b the input buffer * @return the factory */ public static InputSupplier<ByteArrayInputStream> newInputStreamSupplier( byte[] b) { return newInputStreamSupplier(b, 0, b.length); }
/** * Returns a factory that will supply instances of * {@link ByteArrayInputStream} that read from the given byte array. * * @param b the input buffer * @return the factory */ public static InputSupplier<ByteArrayInputStream> newInputStreamSupplier( byte[] b) { return newInputStreamSupplier(b, 0, b.length); }
public static InputSupplier<? extends InputStream> of(String in) { byte[] bytes = checkNotNull(in, "in").getBytes(Charsets.UTF_8); return ByteStreams.newInputStreamSupplier(bytes); } }
/** * Executes {@link Pems#x509Certificate(InputSupplier, CertificateFactory)} on the string which contains an X.509 * certificate in PEM format. * * @param pem * certificate in pem encoded format. * @see Pems#x509Certificate(InputSupplier, CertificateFactory) */ public static X509Certificate x509Certificate(String pem) throws IOException, CertificateException { return x509Certificate(ByteStreams.newInputStreamSupplier( pem.getBytes(Charsets.UTF_8)), null); }
protected Payload doSlice(byte[] content, long offset, long length) { Payload returnVal; checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array"); checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array"); returnVal = new InputStreamSupplierPayload( ByteStreams.newInputStreamSupplier(content, (int) offset, (int) length)); return returnVal; }
/** * Executes {@link Pems#x509Certificate(InputSupplier, CertificateFactory)} on the string which contains an X.509 * certificate in PEM format. * * @param pem * certificate in pem encoded format. * @see Pems#x509Certificate(InputSupplier, CertificateFactory) */ public static X509Certificate x509Certificate(String pem) throws IOException, CertificateException { return x509Certificate(ByteStreams.newInputStreamSupplier( pem.getBytes(Charsets.UTF_8)), null); }
private DataSegment createDescriptorFile(DataSegment segment, File outDir) throws IOException { File descriptorFile = new File(outDir, "descriptor.json"); log.info("Creating descriptor file at[%s]", descriptorFile); Files.copy(ByteStreams.newInputStreamSupplier(jsonMapper.writeValueAsBytes(segment)), descriptorFile); return segment; }
/** * Executes {@link Pems#publicKeySpec(InputSupplier)} on the string which contains an encoded public key in PEM * format. * * @param pem * public key in pem encoded format. * @see Pems#publicKeySpec(InputSupplier) */ public static KeySpec publicKeySpec(String pem) throws IOException { return publicKeySpec(ByteStreams.newInputStreamSupplier( pem.getBytes(Charsets.UTF_8))); }
protected Payload doSlice(byte[] content, long offset, long length) { Payload returnVal; checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array"); checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array"); returnVal = new InputStreamSupplierPayload( ByteStreams.newInputStreamSupplier(content, (int) offset, (int) length)); return returnVal; }
protected Payload doSlice(byte[] content, long offset, long length) { Payload returnVal; checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array"); checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array"); returnVal = new InputStreamSupplierPayload( ByteStreams.newInputStreamSupplier(content, (int) offset, (int) length)); return returnVal; }
@Override public PrivateKey load(Credentials in) { try { return crypto.rsaKeyFactory().generatePrivate( privateKeySpec(ByteStreams.newInputStreamSupplier(in.credential.getBytes(Charsets.UTF_8)))); } catch (InvalidKeySpecException e) { throw propagate(e); } catch (IOException e) { throw propagate(e); } } }
@Override public PrivateKey load(Credentials in) { try { return crypto.rsaKeyFactory().generatePrivate( privateKeySpec(ByteStreams.newInputStreamSupplier(in.credential.getBytes(Charsets.UTF_8)))); } catch (InvalidKeySpecException e) { throw propagate(e); } catch (IOException e) { throw propagate(e); } } }
private InputSupplier<? extends InputStream> addLengthAndReturnHeaders(String boundaryrn, Part part) { StringBuilder builder = new StringBuilder(dd).append(boundaryrn); for (Entry<String, String> entry : part.getHeaders().entries()) { String header = String.format("%s: %s%s", entry.getKey(), entry.getValue(), rn); builder.append(header); } builder.append(rn); getContentMetadata().setContentLength(getContentMetadata().getContentLength() + builder.length()); return newInputStreamSupplier(builder.toString().getBytes()); }
private InputSupplier<? extends InputStream> addLengthAndReturnHeaders(String boundaryrn, Part part) { StringBuilder builder = new StringBuilder(dd).append(boundaryrn); for (Entry<String, String> entry : part.getHeaders().entries()) { String header = String.format("%s: %s%s", entry.getKey(), entry.getValue(), rn); builder.append(header); } builder.append(rn); getContentMetadata().setContentLength(getContentMetadata().getContentLength() + builder.length()); return newInputStreamSupplier(builder.toString().getBytes()); }
private InputSupplier<? extends InputStream> addLengthAndReturnHeaders(String boundaryrn, Part part) { StringBuilder builder = new StringBuilder(dd).append(boundaryrn); for (Entry<String, String> entry : part.getHeaders().entries()) { String header = String.format("%s: %s%s", entry.getKey(), entry.getValue(), rn); builder.append(header); } builder.append(rn); getContentMetadata().setContentLength(getContentMetadata().getContentLength() + builder.length()); return newInputStreamSupplier(builder.toString().getBytes()); }
private InputSupplier<? extends InputStream> addLengthAndReturnFooter(String boundary) { String end = dd + boundary + dd + rn; getContentMetadata().setContentLength(getContentMetadata().getContentLength() + end.length()); return newInputStreamSupplier(end.getBytes()); }
private File createTestInput() throws IOException { File file = File.createTempFile("testimg", "png"); file.deleteOnExit(); Random random = new Random(); byte[] buffer = new byte[random.nextInt(2 * 1024 * 1024)]; random.nextBytes(buffer); Files.copy(ByteStreams.newInputStreamSupplier(buffer), file); return file; } }
@SuppressWarnings("unchecked") public static InputSupplier<InputStream> getTestDataSupplier() throws IOException { byte[] oneConstitution = toByteArray(new GZIPInputStream(BaseJettyTest.class.getResourceAsStream("/const.txt.gz"))); InputSupplier<ByteArrayInputStream> constitutionSupplier = newInputStreamSupplier(oneConstitution); InputSupplier<InputStream> temp = join(constitutionSupplier); for (int i = 0; i < 100; i++) { temp = join(temp, constitutionSupplier); } return temp; }
@SuppressWarnings("unchecked") public static InputSupplier<InputStream> getTestDataSupplier() throws IOException { byte[] oneConstitution = toByteArray(new GZIPInputStream(BaseJettyTest.class.getResourceAsStream("/const.txt.gz"))); InputSupplier<ByteArrayInputStream> constitutionSupplier = newInputStreamSupplier(oneConstitution); InputSupplier<InputStream> temp = join(constitutionSupplier); // we have to go beyond 5MB per part for (oneHundredOneConstitutionsLength = oneConstitution.length; oneHundredOneConstitutionsLength < 5 * 1024 * 1024; oneHundredOneConstitutionsLength += oneConstitution.length) { temp = join(temp, constitutionSupplier); } return temp; }
@SuppressWarnings("unchecked") public static InputSupplier<InputStream> getTestDataSupplier() throws IOException { byte[] oneConstitution = ByteStreams.toByteArray(new GZIPInputStream(BaseJettyTest.class .getResourceAsStream("/const.txt.gz"))); InputSupplier<ByteArrayInputStream> constitutionSupplier = ByteStreams.newInputStreamSupplier(oneConstitution); InputSupplier<InputStream> temp = ByteStreams.join(constitutionSupplier); for (int i = 0; i < 100; i++) { temp = ByteStreams.join(temp, constitutionSupplier); } oneHundredOneConstitutionsLength = oneConstitution.length * 101l; return temp; }