/** * Reads all data from the given reader. * * @param reader Reader over character data. * * @return Data read from reader. * * @throws StreamException on stream IO errors. */ public static String readAll(final Reader reader) throws StreamException { return readAll(reader, 1024); }
/** * Reads all the data from the given input stream. * * @param input Input stream to read. * * @return Byte array of data read from stream. * * @throws StreamException on stream IO errors. */ public static byte[] readAll(final InputStream input) throws StreamException { return readAll(input, 1024); }
/** * Reads all the data from the file at the given path. * * @param path Path to file. * * @return Byte array of data read from file. * * @throws StreamException on stream IO errors. */ public static byte[] readAll(final String path) throws StreamException { return readAll(new File(path)); }
/** * Reads a DER or PEM-encoded public key from data in the given stream. The {@link InputStream} parameter is closed by * this method. * * @param in Input stream containing an encoded key. * * @return Public key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors. */ public static PublicKey readPublicKey(final InputStream in) throws EncodingException, StreamException { return decodePublicKey(StreamUtil.readAll(in)); }
/** * Reads an encrypted private key from an input stream. Both PKCS#8 and OpenSSL "traditional" formats are supported in * DER or PEM encoding. See {@link #decodePrivateKey(byte[])} for supported asymmetric algorithms. The {@link * InputStream} parameter is closed by this method. * * @param in Input stream containing private key data. * @param password Password used to encrypt private key. * * @return Private key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors. */ public static PrivateKey readPrivateKey(final InputStream in, final char[] password) throws EncodingException, StreamException { return decodePrivateKey(StreamUtil.readAll(in), password); }
/** * Reads an encoded private key from an input stream. Both PKCS#8 and OpenSSL "traditional" formats are supported in * DER or PEM encoding. See {@link #decodePrivateKey(byte[])} for supported asymmetric algorithms. The {@link * InputStream} parameter is closed by this method. * * @param in Input stream containing private key data. * * @return Private key. * * @throws EncodingException on key encoding errors. * @throws StreamException on IO errors reading data from file. */ public static PrivateKey readPrivateKey(final InputStream in) throws EncodingException, StreamException { return decodePrivateKey(StreamUtil.readAll(in)); }
@Override public SecretKey newInstance() throws StreamException { try { return new SecretKeySpec(StreamUtil.readAll(resource.getInputStream()), algorithm); } catch (IOException e) { throw new StreamException(e); } } }
/** * Reads all the data from the given file. * * @param file File to read. * * @return Byte array of data read from file. * * @throws StreamException on stream IO errors. */ public static byte[] readAll(final File file) throws StreamException { final InputStream input = makeStream(file); try { return readAll(input, (int) file.length()); } finally { closeStream(input); } }