protected void serveStaticContent(HttpServletRequest request, HttpServletResponse response, String pathInfo) throws ServletException { InputStream is = getResourceAsStream(pathInfo); if (is == null) { throw new ServletException("Static resource " + pathInfo + " is not available"); } try { int ind = pathInfo.lastIndexOf("."); if (ind != -1 && ind < pathInfo.length()) { String type = getStaticResourceContentType(pathInfo.substring(ind + 1)); if (type != null) { response.setContentType(type); } } String cacheControl = getServletConfig().getInitParameter(STATIC_CACHE_CONTROL); if (cacheControl != null) { response.setHeader("Cache-Control", cacheControl.trim()); } ServletOutputStream os = response.getOutputStream(); IOUtils.copyAndCloseInput(is, os); os.flush(); } catch (IOException ex) { throw new ServletException("Static resource " + pathInfo + " can not be written to the output stream"); } }
public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException { IOUtils.copyAndCloseInput(in, out, bufferSize); }
public static void copyStream(InputStream in, OutputStream out, int bufferSize) throws IOException { IOUtils.copyAndCloseInput(in, out, bufferSize); }
public static void writeUtilsToResponseStream(Class<?> referenceClass, OutputStream outputStream) { InputStream utils = referenceClass.getResourceAsStream(JS_UTILS_PATH); if (utils == null) { throw new RuntimeException("Unable to get stream for " + JS_UTILS_PATH); } try { IOUtils.copyAndCloseInput(utils, outputStream); outputStream.flush(); } catch (IOException e) { throw new RuntimeException("Failed to write javascript utils to HTTP response.", e); } }
protected void handleRangeRequest(InputStream is, OutputStream os, HttpHeaders inHeaders, MultivaluedMap<String, Object> outHeaders) throws IOException { String range = inHeaders.getRequestHeaders().getFirst("Range"); if (range == null) { IOUtils.copyAndCloseInput(is, os, bufferSize); } else { // implement } }
@Override protected byte[] getBytes(Object object) { DataSource dataSource = (DataSource) object; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos); } catch (IOException e) { throw new RuntimeException(e); } return baos.toByteArray(); } }
public static void transferTo(InputStream inputStream, File destinationFile) throws IOException { if (Transferable.class.isAssignableFrom(inputStream.getClass())) { ((Transferable)inputStream).transferTo(destinationFile); } else { try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) { copyAndCloseInput(inputStream, out); } } }
public static void transferTo(InputStream inputStream, File destinationFile) throws IOException { if (Transferable.class.isAssignableFrom(inputStream.getClass())) { ((Transferable)inputStream).transferTo(destinationFile); } else { try (OutputStream out = Files.newOutputStream(destinationFile.toPath())) { copyAndCloseInput(inputStream, out); } } }
protected void handleRangeRequest(InputStream is, OutputStream os, HttpHeaders inHeaders, MultivaluedMap<String, Object> outHeaders) throws IOException { String range = inHeaders.getRequestHeaders().getFirst("Range"); if (range == null) { IOUtils.copyAndCloseInput(is, os); } else { // implement } }
@Override protected byte[] getBytes(Object object) { DataSource dataSource = (DataSource) object; ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos); } catch (IOException e) { throw new RuntimeException(e); } return baos.toByteArray(); } }
public void writeCacheTo(OutputStream out) throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream)currentStream).writeTo(out); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file InputStream fin = createInputStream(tempFile); IOUtils.copyAndCloseInput(fin, out); } }
public void writeCacheTo(OutputStream out) throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream)currentStream).writeTo(out); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file InputStream fin = createInputStream(tempFile); IOUtils.copyAndCloseInput(fin, out); } }
public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { DataSource ds = DataSource.class.isAssignableFrom(cls) ? (DataSource)src : ((DataHandler)src).getDataSource(); if (useDataSourceContentType) { setContentTypeIfNeeded(type, headers, ds.getContentType()); } IOUtils.copyAndCloseInput(ds.getInputStream(), os); }
public void writeTo(T src, Class<?> cls, Type genericType, Annotation[] annotations, MediaType type, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { DataSource ds = DataSource.class.isAssignableFrom(cls) ? (DataSource)src : ((DataHandler)src).getDataSource(); if (useDataSourceContentType) { setContentTypeIfNeeded(type, headers, ds.getContentType()); } IOUtils.copyAndCloseInput(ds.getInputStream(), os); }
public void performTransformation(Message message) { Reader transformedReader = null; try { transformedReader = XSLTUtils.transform(xsltTemplate, getReader()); IOUtils.copyAndCloseInput(transformedReader, origWriter, IOUtils.DEFAULT_BUFFER_SIZE); message.setContent(Writer.class, origWriter); } catch (IOException e) { throw new Fault("READER_COPY", LOG, e, e.getMessage()); } } }
@Test public void testPostPetStatus2() throws Exception { Socket s = new Socket("localhost", Integer.parseInt(PORT)); IOUtils.copyAndCloseInput(getClass().getResource("resources/formRequest.txt").openStream(), s.getOutputStream()); s.getOutputStream().flush(); try { assertTrue("Wrong status returned", getStringFromInputStream(s.getInputStream()) .contains("open")); } finally { s.close(); } }
private void handleReader(Message message, Reader reader) throws IOException { CachedWriter writer = new CachedWriter(); IOUtils.copyAndCloseInput(reader, writer); message.setContent(Reader.class, writer.getReader()); message.setContent(CachedWriter.class, writer); }
private void handleReader(Message message, Reader reader) throws IOException { CachedWriter writer = new CachedWriter(); IOUtils.copyAndCloseInput(reader, writer); message.setContent(Reader.class, writer.getReader()); message.setContent(CachedWriter.class, writer); }
private InputStream copyIn(InputStream in) throws Exception { try (CachedOutputStream bos = new CachedOutputStream()) { IOUtils.copyAndCloseInput(in, bos); in = bos.getInputStream(); bos.close(); return in; } } private String getStringFromInputStream(InputStream in) throws Exception {
protected void copyInputToOutput(InputStream is, OutputStream os, MultivaluedMap<String, Object> outHeaders) throws IOException { if (isRangeSupported()) { Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage(); handleRangeRequest(is, os, new HttpHeadersImpl(inMessage), outHeaders); } else if (closeResponseInputStream) { IOUtils.copyAndCloseInput(is, os); } else { IOUtils.copy(is, os); } }