/** * Completely reads the given stream's bytes into a * {@code ByteString}, blocking if necessary until all bytes are * read through to the end of the stream. * * <b>Performance notes:</b> The returned {@code ByteString} is an * immutable tree of byte arrays ("chunks") of the stream data. The * chunkSize parameter sets the size of these byte arrays. In * particular, if the chunkSize is precisely the same as the length * of the stream, unnecessary allocations and copies will be * avoided. Otherwise, the chunks will be of the given size, except * for the last chunk, which will be resized (via a reallocation and * copy) to contain the remainder of the stream. * * @param streamToDrain The source stream, which is read completely * but not closed. * @param chunkSize The size of the chunks in which to read the * stream. * @return A new {@code ByteString} which is made up of chunks of * the given size. * @throws IOException IOException is thrown if there is a problem * reading the underlying stream. */ public static ByteString readFrom(InputStream streamToDrain, int chunkSize) throws IOException { return readFrom(streamToDrain, chunkSize, chunkSize); }
/** * Completely reads the given stream's bytes into a * {@code ByteString}, blocking if necessary until all bytes are * read through to the end of the stream. * * <b>Performance notes:</b> The returned {@code ByteString} is an * immutable tree of byte arrays ("chunks") of the stream data. The * first chunk is small, with subsequent chunks each being double * the size, up to 8K. If the caller knows the precise length of * the stream and wishes to avoid all unnecessary copies and * allocations, consider using the two-argument version of this * method, below. * * @param streamToDrain The source stream, which is read completely * but not closed. * @return A new {@code ByteString} which is made up of chunks of * various sizes, depending on the behavior of the underlying * stream. * @throws IOException IOException is thrown if there is a problem * reading the underlying stream. */ public static ByteString readFrom(InputStream streamToDrain) throws IOException { return readFrom( streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE); }
/** * Completely reads the given stream's bytes into a * {@code ByteString}, blocking if necessary until all bytes are * read through to the end of the stream. * * <b>Performance notes:</b> The returned {@code ByteString} is an * immutable tree of byte arrays ("chunks") of the stream data. The * first chunk is small, with subsequent chunks each being double * the size, up to 8K. If the caller knows the precise length of * the stream and wishes to avoid all unnecessary copies and * allocations, consider using the two-argument version of this * method, below. * * @param streamToDrain The source stream, which is read completely * but not closed. * @return A new {@code ByteString} which is made up of chunks of * various sizes, depending on the behavior of the underlying * stream. * @throws IOException IOException is thrown if there is a problem * reading the underlying stream. */ public static ByteString readFrom(InputStream streamToDrain) throws IOException { return readFrom( streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE); }
/** * Completely reads the given stream's bytes into a * {@code ByteString}, blocking if necessary until all bytes are * read through to the end of the stream. * * <b>Performance notes:</b> The returned {@code ByteString} is an * immutable tree of byte arrays ("chunks") of the stream data. The * first chunk is small, with subsequent chunks each being double * the size, up to 8K. If the caller knows the precise length of * the stream and wishes to avoid all unnecessary copies and * allocations, consider using the two-argument version of this * method, below. * * @param streamToDrain The source stream, which is read completely * but not closed. * @return A new {@code ByteString} which is made up of chunks of * various sizes, depending on the behavior of the underlying * stream. * @throws IOException IOException is thrown if there is a problem * reading the underlying stream. */ public static ByteString readFrom(InputStream streamToDrain) throws IOException { return readFrom( streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE); }
/** * Completely reads the given stream's bytes into a * {@code ByteString}, blocking if necessary until all bytes are * read through to the end of the stream. * * <b>Performance notes:</b> The returned {@code ByteString} is an * immutable tree of byte arrays ("chunks") of the stream data. The * chunkSize parameter sets the size of these byte arrays. In * particular, if the chunkSize is precisely the same as the length * of the stream, unnecessary allocations and copies will be * avoided. Otherwise, the chunks will be of the given size, except * for the last chunk, which will be resized (via a reallocation and * copy) to contain the remainder of the stream. * * @param streamToDrain The source stream, which is read completely * but not closed. * @param chunkSize The size of the chunks in which to read the * stream. * @return A new {@code ByteString} which is made up of chunks of * the given size. * @throws IOException IOException is thrown if there is a problem * reading the underlying stream. */ public static ByteString readFrom(InputStream streamToDrain, int chunkSize) throws IOException { return readFrom(streamToDrain, chunkSize, chunkSize); }
/** * Completely reads the given stream's bytes into a * {@code ByteString}, blocking if necessary until all bytes are * read through to the end of the stream. * * <b>Performance notes:</b> The returned {@code ByteString} is an * immutable tree of byte arrays ("chunks") of the stream data. The * chunkSize parameter sets the size of these byte arrays. In * particular, if the chunkSize is precisely the same as the length * of the stream, unnecessary allocations and copies will be * avoided. Otherwise, the chunks will be of the given size, except * for the last chunk, which will be resized (via a reallocation and * copy) to contain the remainder of the stream. * * @param streamToDrain The source stream, which is read completely * but not closed. * @param chunkSize The size of the chunks in which to read the * stream. * @return A new {@code ByteString} which is made up of chunks of * the given size. * @throws IOException IOException is thrown if there is a problem * reading the underlying stream. */ public static ByteString readFrom(InputStream streamToDrain, int chunkSize) throws IOException { return readFrom(streamToDrain, chunkSize, chunkSize); }