public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }
public static List<String> readAllLines(InputStream input) throws IOException { final List<String> lines = new ArrayList<>(); readAllLines(input, lines::add); return lines; }
public static int readFully(InputStream reader, byte[] dest) throws IOException { return readFully(reader, dest, 0, dest.length); }
public static String copyToStringFromClasspath(ClassLoader classLoader, String path) throws IOException { InputStream is = classLoader.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class loader [" + classLoader + "]"); } return Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8)); }
@Override public String toString() { try { if (klass != null) { InputStream inputStream = klass.getResourceAsStream(path); if (inputStream == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class [" + klass.getName() + "]"); } return Streams.copyToString(new InputStreamReader(inputStream, "UTF-8")); } else { return Streams.copyToStringFromClasspath(classLoader, path); } } catch (IOException e) { throw new EsSetupRuntimeException(e); } } }
CompressibleBytesOutputStream(BytesStream bytesStreamOutput, boolean shouldCompress) throws IOException { this.bytesStreamOutput = bytesStreamOutput; this.shouldCompress = shouldCompress; if (shouldCompress) { this.stream = CompressorFactory.COMPRESSOR.streamOutput(Streams.flushOnCloseStream(bytesStreamOutput)); } else { this.stream = bytesStreamOutput; } }
public JettyHttpServerRestRequest(HttpServletRequest request) throws IOException { this.request = request; this.opaqueId = request.getHeader("X-Opaque-Id"); this.method = Method.valueOf(request.getMethod()); this.params = new HashMap<String, String>(); if (request.getQueryString() != null) { RestUtils.decodeQueryString(request.getQueryString(), 0, params); } content = new BytesArray(Streams.copyToByteArray(request.getInputStream())); request.setAttribute(REQUEST_CONTENT_ATTRIBUTE, content); }
public static String getRiverVersion() { String version = "Undefined"; try { String properties = Streams.copyToStringFromClasspath("/org/elasticsearch/river/mongodb/es-build.properties"); Properties props = new Properties(); props.load(new FastStringReader(properties)); String ver = props.getProperty("version", "undefined"); String hash = props.getProperty("hash", "undefined"); if (!"undefined".equals(hash)) { hash = hash.substring(0, 7); } String timestamp = "undefined"; String gitTimestampRaw = props.getProperty("timestamp"); if (gitTimestampRaw != null) { timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw)); } version = String.format("version[%s] - hash[%s] - time[%s]", ver, hash, timestamp); } catch (Exception ex) { } return version; }
public static String copyToStringFromClasspath(String path) throws IOException { InputStream is = Streams.class.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath"); } return Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8)); }
@Override public String toString() { try { if (klass != null) { InputStream inputStream = klass.getResourceAsStream(path); if (inputStream == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class [" + klass.getName() + "]"); } return Streams.copyToString(new InputStreamReader(inputStream, "UTF-8")); } else { return Streams.copyToStringFromClasspath(classLoader, path); } } catch (IOException e) { throw new EsSetupRuntimeException(e); } } }
OutputStream unclosableOutputStream = Streams.flushOnCloseStream(bytesOutput()); XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(responseContentType), unclosableOutputStream, includes, excludes);
public TomcatHttpServerRestRequest(final HttpServletRequest request) throws IOException { this.request = request; opaqueId = request.getHeader("X-Opaque-Id"); method = Method.valueOf(request.getMethod()); params = new HashMap<String, String>(); log.debug("HttpServletRequest impl class: " + request.getClass()); log.debug("HttpServletRequest ru: " + request.getRemoteUser()); log.debug("HttpServletRequest up: " + request.getUserPrincipal()); //log.debug("HttpServletRequest up: " + request.getUserPrincipal().getClass().toString()); if (request.getQueryString() != null) { RestUtils.decodeQueryString(request.getQueryString(), 0, params); } content = new BytesArray(Streams.copyToByteArray(request .getInputStream())); request.setAttribute(REQUEST_CONTENT_ATTRIBUTE, content); }
Map<String, String> loadFromClasspath(String resourceName) throws IOException { InputStream is = this.getClass().getResourceAsStream(resourceName); if (is == null) { throw new FileNotFoundException("Unable to find file " + MESSAGES_FILE); } SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName); return settingsLoader.load(Streams.copyToString(new InputStreamReader(is, "UTF-8"))); }
/** * 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 int readFully(Reader reader, char[] dest) throws IOException { return readFully(reader, dest, 0, dest.length); }
int[] width = buildWidths(table, request, verbose, headers); BytesStream bytesOut = Streams.flushOnCloseStream(channel.bytesOutput()); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut); int lastHeader = headers.size() - 1;
public static List<String> readAllLines(InputStream input) throws IOException { final List<String> lines = new ArrayList<>(); readAllLines(input, lines::add); return lines; }
long version = Long.parseLong(stateFile.getName().substring("global-".length())); if (version > highestVersion) { byte[] data = Streams.copyToByteArray(new FileInputStream(stateFile)); if (data.length == 0) { continue;
/** * Loads settings from a stream that represents them using the * {@link SettingsLoaderFactory#loaderFromResource(String)}. */ public Builder loadFromStream(String resourceName, InputStream is) throws IOException { SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName); // NOTE: copyToString will close the input stream Map<String, String> loadedSettings = settingsLoader.load(Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8))); put(loadedSettings); return this; }
public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, new byte[BUFFER_SIZE]); }