public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }
/** * Copy the contents of the given Reader into a String. * Closes the reader when done. * * @param in the reader to copy from * @return the String that has been copied to * @throws IOException in case of I/O errors */ public static String copyToString(Reader in) throws IOException { StringWriter out = new StringWriter(); copy(in, out); return out.toString(); }
public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }
public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }
public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }
public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }
/** * Copy the contents of the given Reader into a String. * Closes the reader when done. * * @param in the reader to copy from * @return the String that has been copied to * @throws IOException in case of I/O errors */ public static String copyToString(Reader in) throws IOException { StringWriter out = new StringWriter(); copy(in, out); return out.toString(); }
/** * Copy the contents of the given Reader into a String. * Closes the reader when done. * * @param in the reader to copy from * @return the String that has been copied to * @throws IOException in case of I/O errors */ public static String copyToString(Reader in) throws IOException { StringWriter out = new StringWriter(); copy(in, out); return out.toString(); }
/** * Copy the contents of the given Reader into a String. * Closes the reader when done. * * @param in the reader to copy from * @return the String that has been copied to * @throws IOException in case of I/O errors */ public static String copyToString(Reader in) throws IOException { StringWriter out = new StringWriter(); copy(in, out); return out.toString(); }
/** * Copy the contents of the given Reader into a String. * Closes the reader when done. * * @param in the reader to copy from * @return the String that has been copied to * @throws IOException in case of I/O errors */ public static String copyToString(Reader in) throws IOException { StringWriter out = new StringWriter(); copy(in, out); return out.toString(); }
public String taskResultIndexMapping() { try (InputStream is = getClass().getResourceAsStream(TASK_RESULT_INDEX_MAPPING_FILE)) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(is, out); return out.toString(IOUtils.UTF_8); } catch (Exception e) { logger.error( (Supplier<?>) () -> new ParameterizedMessage( "failed to create tasks results index template [{}]", TASK_RESULT_INDEX_MAPPING_FILE), e); throw new IllegalStateException("failed to create tasks results index template [" + TASK_RESULT_INDEX_MAPPING_FILE + "]", e); } } }
@Override public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException { try (OutputStream stream = createOutput(blobName)) { Streams.copy(inputStream, stream); } }
public static byte[] copyToBytesFromClasspath(String path) throws IOException { try (InputStream is = Streams.class.getResourceAsStream(path)) { if (is == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath"); } try (BytesStreamOutput out = new BytesStreamOutput()) { Streams.copy(is, out); return BytesReference.toBytes(out.bytes()); } } }
@Override public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException { final Path file = path.resolve(blobName); try (OutputStream outputStream = Files.newOutputStream(file)) { Streams.copy(inputStream, outputStream, new byte[blobStore.bufferSizeInBytes()]); } IOUtils.fsync(file, false); IOUtils.fsync(path, true); }
@Override public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException { if (blobExists(blobName)) { throw new FileAlreadyExistsException("blob [" + blobName + "] already exists, cannot overwrite"); } final Path file = path.resolve(blobName); try (OutputStream outputStream = Files.newOutputStream(file, StandardOpenOption.CREATE_NEW)) { Streams.copy(inputStream, outputStream, new byte[blobStore.bufferSizeInBytes()]); } IOUtils.fsync(file, false); IOUtils.fsync(path, true); }
void handleFavicon(RestRequest request, RestChannel channel) { if (request.method() == RestRequest.Method.GET) { try { try (InputStream stream = getClass().getResourceAsStream("/config/favicon.ico")) { ByteArrayOutputStream out = new ByteArrayOutputStream(); Streams.copy(stream, out); BytesRestResponse restResponse = new BytesRestResponse(RestStatus.OK, "image/x-icon", out.toByteArray()); channel.sendResponse(restResponse); } } catch (IOException e) { channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } } else { channel.sendResponse(new BytesRestResponse(FORBIDDEN, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY)); } }
private static BytesReference uncompress(BytesReference bytes, Compressor compressor) throws IOException { StreamInput compressed = compressor.streamInput(bytes.streamInput()); BytesStreamOutput bStream = new BytesStreamOutput(); Streams.copy(compressed, bStream); compressed.close(); return bStream.bytes(); } }
long readSnapshotIndexLatestBlob() throws IOException { try (InputStream blob = snapshotsBlobContainer.readBlob(INDEX_LATEST_BLOB)) { BytesStreamOutput out = new BytesStreamOutput(); Streams.copy(blob, out); return Numbers.bytesToLong(out.bytes().toBytesRef()); } }
private static BytesReference uncompress(BytesReference bytes, Compressor compressor) throws IOException { StreamInput compressed = compressor.streamInput(bytes.streamInput()); BytesStreamOutput bStream = new BytesStreamOutput(); Streams.copy(compressed, bStream); compressed.close(); return bStream.bytes(); } }
@Override public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException { if (mayWriteRawData(contentType) == false) { // EMPTY is safe here because we never call namedObject when writing raw data try (XContentParser parser = XContentFactory.xContent(contentType).createParser(NamedXContentRegistry.EMPTY, content)) { parser.nextToken(); writeFieldName(name); copyCurrentStructure(parser); } } else { writeStartRaw(name); flush(); Streams.copy(content, os); writeEndRaw(); } }