csnew.flush(); IOUtils.closeQuietly(csnew);
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } throw new IOException("Unknown format of currentStream"); } // read the file try (InputStream fin = createInputStream(tempFile)) { return IOUtils.readBytesFromStream(fin); } }
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } throw new IOException("Unknown format of currentStream"); } // read the file try (InputStream fin = createInputStream(tempFile)) { return IOUtils.readBytesFromStream(fin); } }
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 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 byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file InputStream fin = createInputStream(tempFile); return IOUtils.readBytesFromStream(fin); } }
public byte[] getBytes() throws IOException { flush(); if (inmem) { if (currentStream instanceof ByteArrayOutputStream) { return ((ByteArrayOutputStream)currentStream).toByteArray(); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file InputStream fin = createInputStream(tempFile); return IOUtils.readBytesFromStream(fin); } }
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(StringBuilder out, String charsetName) throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingByteArrayOutputStream) { LoadingByteArrayOutputStream lout = (LoadingByteArrayOutputStream)currentStream; out.append(IOUtils.newStringFromBytes(lout.getRawBytes(), charsetName, 0, lout.size())); } else if (currentStream instanceof ByteArrayOutputStream) { byte[] bytes = ((ByteArrayOutputStream)currentStream).toByteArray(); out.append(IOUtils.newStringFromBytes(bytes, charsetName)); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file try (InputStream fin = createInputStream(tempFile); Reader reader = new InputStreamReader(fin, charsetName)) { char[] bytes = new char[1024]; int x = reader.read(bytes); while (x != -1) { out.append(bytes, 0, x); x = reader.read(bytes); } } } }
public void writeCacheTo(StringBuilder out, String charsetName) throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingByteArrayOutputStream) { LoadingByteArrayOutputStream lout = (LoadingByteArrayOutputStream)currentStream; out.append(IOUtils.newStringFromBytes(lout.getRawBytes(), charsetName, 0, lout.size())); } else if (currentStream instanceof ByteArrayOutputStream) { byte[] bytes = ((ByteArrayOutputStream)currentStream).toByteArray(); out.append(IOUtils.newStringFromBytes(bytes, charsetName)); } else { throw new IOException("Unknown format of currentStream"); } } else { // read the file try (InputStream fin = createInputStream(tempFile); Reader reader = new InputStreamReader(fin, charsetName)) { char[] bytes = new char[1024]; int x = reader.read(bytes); while (x != -1) { out.append(bytes, 0, x); x = reader.read(bytes); } } } }
public class StringContentRequestHandler implements RequestHandler { private static final Logger logger = LoggerFactory.getLogger(RawContentRequestHandler.class); public Response handleRequest(Message m, ClassResourceInfo resourceClass) { InputStream is = m.getContent(InputStream.class); try { CachedOutputStream bos = new CachedOutputStream(); IOUtils.copy(is, bos); bos.flush(); is.close(); m.setContent(InputStream.class, bos.getInputStream()); StringBuilder builder = new StringBuilder(); bos.writeCacheTo(builder, "utf-8"); m.setContent(String.class, builder.toString()); return null; } catch (IOException ex) { logger.error("IOException on getting raw content", ex); return null; } } }
private void closeConnectionStream(SoapMessage soapMessage) throws IOException { InputStream is = soapMessage.getContent(InputStream.class); if (is != null) { CachedOutputStream bos = new CachedOutputStream(); try { IOUtils.copy(is, bos); } catch (IOException e) { //the is could be already closed for ws-rm, just ignore it. } bos.flush(); is.close(); soapMessage.setContent(InputStream.class, bos.getInputStream()); bos.close(); } }
void send(boolean complete) throws IOException { if (out == null) { return; } if (response.getStatus() >= 400) { int i = response.getStatus(); response.setStatus(200); response.addIntHeader(WebSocketUtils.SC_KEY, i); } out.flush(); out.lockOutputStream(); out.writeCacheTo(delegate); delegate.flush(); out.close(); out = null; }
void send(boolean complete) throws IOException { if (out == null) { return; } if (response.getStatus() >= 400) { int i = response.getStatus(); response.setStatus(200); response.addIntHeader(WebSocketUtils.SC_KEY, i); } out.flush(); out.lockOutputStream(); out.writeCacheTo(delegate); delegate.flush(); out.close(); out = null; }
private void handleInputStream(Message message, InputStream is) throws IOException { CachedOutputStream bos = new CachedOutputStream(); if (threshold > 0) { bos.setThreshold(threshold); } // use the appropriate input stream and restore it later InputStream bis = is instanceof DelegatingInputStream ? ((DelegatingInputStream)is).getInputStream() : is; // only copy up to the limit since that's all we need to log // we can stream the rest IOUtils.copyAtLeast(bis, bos, limit == -1 ? Integer.MAX_VALUE : limit); bos.flush(); bis = new SequenceInputStream(bos.getInputStream(), bis); // restore the delegating input stream or the input stream if (is instanceof DelegatingInputStream) { ((DelegatingInputStream)is).setInputStream(bis); } else { message.setContent(InputStream.class, bis); } message.setContent(CachedOutputStream.class, bos); }
private void handleInputStream(Message message, InputStream is) throws IOException { CachedOutputStream bos = new CachedOutputStream(); if (threshold > 0) { bos.setThreshold(threshold); } // use the appropriate input stream and restore it later InputStream bis = is instanceof DelegatingInputStream ? ((DelegatingInputStream)is).getInputStream() : is; // only copy up to the limit since that's all we need to log // we can stream the rest IOUtils.copyAtLeast(bis, bos, limit == -1 ? Integer.MAX_VALUE : limit); bos.flush(); bis = new SequenceInputStream(bos.getInputStream(), bis); // restore the delegating input stream or the input stream if (is instanceof DelegatingInputStream) { ((DelegatingInputStream)is).setInputStream(bis); } else { message.setContent(InputStream.class, bis); } message.setContent(CachedOutputStream.class, bos); }
/** * Copied from LoggingInInterceptor * * @param soapMessage */ private void getSoapRequest(Message soapMessage, ExchangeData exchange) { InputStream is = soapMessage.getContent(InputStream.class); if (is != null) { CachedOutputStream bos = new CachedOutputStream(); try { IOUtils.copy(is, bos); bos.flush(); is.close(); soapMessage.setContent(InputStream.class, bos.getInputStream()); StringBuilder builder = new StringBuilder(); bos.writeCacheTo(builder, bos.size()); bos.close(); exchange.setRequest(builder.toString()); exchange.setRequestSize((int)bos.size()); } catch (IOException e) { throw new Fault(e); } } }
public void handleMessage(Message message) throws Fault { InputStream is = message.getContent(InputStream.class); if (is != null) { CachedOutputStream bos = new CachedOutputStream(); try { //intend to change response as malformed message is = getClass().getClassLoader().getResourceAsStream( "org/apache/cxf/systest/dispatch/resources/GreetMeDocLiteralRespMalformed.xml"); IOUtils.copy(is, bos); bos.flush(); is.close(); message.setContent(InputStream.class, bos.getInputStream()); bos.close(); message.setContent(InputStream.class, bos.getInputStream()); } catch (IOException e) { throw new Fault(e); } } }
public static void encodeRMContent(RMMessage rmmsg, Message msg, InputStream msgContent) throws IOException { CachedOutputStream cos = new CachedOutputStream(); if (msg.getAttachments() == null) { rmmsg.setContentType((String)msg.get(Message.CONTENT_TYPE)); IOUtils.copyAndCloseInput(msgContent, cos); cos.flush(); rmmsg.setContent(cos); } else { MessageImpl msgImpl1 = new MessageImpl(); msgImpl1.setContent(OutputStream.class, cos); msgImpl1.setAttachments(msg.getAttachments()); msgImpl1.put(Message.CONTENT_TYPE, msg.get(Message.CONTENT_TYPE)); msgImpl1.setContent(InputStream.class, msgContent); AttachmentSerializer serializer = new AttachmentSerializer(msgImpl1); serializer.setXop(false); serializer.writeProlog(); // write soap root message into cached output stream IOUtils.copyAndCloseInput(msgContent, cos); cos.flush(); serializer.writeAttachments(); rmmsg.setContentType((String) msgImpl1.get(Message.CONTENT_TYPE)); rmmsg.setContent(cos); } }