public static String readBody(BufferedReader reader) throws IOException { final StringWriter body; body = new StringWriter(); IOHelper.copyStream(reader, body, 1024); return body.toString(); }
public static String readBody(BufferedReader reader) throws IOException { final StringWriter body; body = new StringWriter(); IOHelper.copyStream(reader, body, 1024); return body.toString(); }
/** * Copy remaining stream content to another stream. * * @param in Input stream to copy (remaining) content from. Cannot be null. * @param out Output stream to copy content to. Cannot be null. * @param copyBufferSize Size of the maximum chunk of data that will be copied in one step. A buffer a this * size will be allocated internally so beware of the usual speed vs. memory tradeoff. * Must be strictly positive. * @throws java.io.IOException on IO error. */ public static void copyStream(InputStream in, Writer out, int copyBufferSize) throws IOException { InputStreamReader reader = null; try { reader = new InputStreamReader(in); copyStream(reader, out, copyBufferSize); } finally { close(reader); } out.flush(); }
/** * Copy remaining stream content to another stream. * * @param in Input stream to copy (remaining) content from. Cannot be null. * @param out Output stream to copy content to. Cannot be null. * @param copyBufferSize Size of the maximum chunk of data that will be copied in one step. A buffer a this * size will be allocated internally so beware of the usual speed vs. memory tradeoff. * Must be strictly positive. * @throws java.io.IOException on IO error. */ public static void copyStream(InputStream in, Writer out, int copyBufferSize) throws IOException { InputStreamReader reader = null; try { reader = new InputStreamReader(in); copyStream(reader, out, copyBufferSize); } finally { close(reader); } out.flush(); }
/** * Copy remaining stream content to another stream. * * @param in Input stream to copy (remaining) content from. Cannot be null. * @param out Output stream to copy content to. Cannot be null. * @param copyBufferSize Size of the maximum chunk of data that will be copied in one step. A buffer a this * size will be allocated internally so beware of the usual speed vs. memory tradeoff. * Must be strictly positive. * @throws java.io.IOException on IO error. */ public static void copyStream(InputStream in, Writer out, int copyBufferSize) throws IOException { InputStreamReader reader = null; try { reader = new InputStreamReader(in); copyStream(reader, out, copyBufferSize); } finally { close(reader); } out.flush(); }
public String retrieveContent(String resourcePath) { final StringWriter writer = new StringWriter(); InputStream inputStream = null; URL resource; try { resource = root.getResource(resourcePath); if (null == resource) { throw new IllegalStateException("Could not find '" + resourcePath + "' in classpath. Root is " + root); } inputStream = resource.openStream(); IOHelper.copyStream(inputStream, writer, COPY_BUFFER_SIZE); return writer.toString(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOHelper.close(writer); IOHelper.close(inputStream); } }
public String retrieveContent(String resourcePath) { final StringWriter writer = new StringWriter(); InputStream inputStream = null; URL resource; try { resource = root.getResource(resourcePath); if (null == resource) { throw new IllegalStateException("Could not find '" + resourcePath + "' in classpath. Root is " + root); } inputStream = resource.openStream(); IOHelper.copyStream(inputStream, writer, COPY_BUFFER_SIZE); return writer.toString(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOHelper.close(writer); IOHelper.close(inputStream); } }
public String retrieveContent(String resourcePath) { final StringWriter writer = new StringWriter(); InputStream inputStream = null; URL resource; try { resource = root.getResource(resourcePath); if (null == resource) { throw new IllegalStateException("Could not find '" + resourcePath + "' in classpath. Root is " + root); } inputStream = resource.openStream(); IOHelper.copyStream(inputStream, writer, COPY_BUFFER_SIZE); return writer.toString(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOHelper.close(writer); IOHelper.close(inputStream); } }