Refine search
@Override public InputStream getInputStream() throws IOException { LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(); writeTo(bout); return bout.createInputStream(); } @Override
if (buffer != null && buffer.size() > 0) { thresholdNotReached(); LoadingByteArrayOutputStream tmp = buffer; buffer = null; super.write(tmp.getRawBytes(), 0, tmp.size());
} else { writingHeaders = true; bout.reset(); writer.append("--").append(boundary).append("\r\n"); writer.append("Content-Type: ").append(rootPart.getContentType()).append("\r\n"); writer.append("Content-ID: <").append(start).append(">\r\n\r\n"); writer.flush(); current = bout.createInputStream(); att = atts.next(); writingHeaders = true; bout.reset(); writer.append("\r\n"); writer.append("--").append(boundary).append("\r\n"); current = bout.createInputStream();
/** * Load the InputStream into memory and return a ByteArrayInputStream that * represents it. Closes the in stream. * * @param in * @throws IOException */ public static ByteArrayInputStream loadIntoBAIS(InputStream in) throws IOException { int i = in.available(); if (i < DEFAULT_BUFFER_SIZE) { i = DEFAULT_BUFFER_SIZE; } LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(i); copy(in, bout); in.close(); return bout.createInputStream(); }
out = new LoadingByteArrayOutputStream(); InputStream in = ac.getInputStream(); IOUtils.copyAndCloseInput(in, out); } else { if (inmem) { currentStream.close(); if (copyOldContent) { InputStream fin = createInputStream(tempFile); IOUtils.copyAndCloseInput(fin, out); deleteTempFile(); inmem = true;
CachedOutputStream cos = new CachedOutputStream(); IOUtils.copyAndCloseInput(cw.getOutputStream().createInputStream(), cos); cos.flush(); InputStream is = cos.getInputStream(); message.put(RMMessageConstants.SAVED_CONTENT, cos); RMManager manager = getManager();
public void handleMessage(Message message) throws Fault { InputStream is = message.getContent(InputStream.class); if (is == null) { return; } LoadingByteArrayOutputStream bos = new LoadingByteArrayOutputStream(); try { IOUtils.copy(is, bos); is.close(); bos.close(); byte[] bytes = bos.toByteArray(); synchronized (inbound) { inbound.add(bytes); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("inbound: " + bos.toString()); } ByteArrayInputStream bis = bos.createInputStream(); message.setContent(InputStream.class, bis); } catch (Exception ex) { ex.printStackTrace(); } }
LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream(); writer = StaxUtils.createXMLStreamWriter(out); StaxUtils.copy(el, writer); writer.flush(); schemaSourcesMap.put(si.getSystemId() + ":" + si.getNamespaceURI(), out.toByteArray()); LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream(); if (ins == null) { sch.write(out); } else { IOUtils.copyAndCloseInput(ins, out); + sch.getTargetNamespace(), out.toByteArray()); Source source = new StreamSource(out.createInputStream(), sch.getSourceURI()); schemaSourcesMap2.put(sch.getSourceURI() + ":" + sch.getTargetNamespace(), source);
public void writeCacheTo(StringBuilder out, String charsetName, long limit) throws IOException { flush(); if (totalLength < limit || limit == -1) { writeCacheTo(out, charsetName); return; if (currentStream instanceof LoadingByteArrayOutputStream) { LoadingByteArrayOutputStream lout = (LoadingByteArrayOutputStream)currentStream; out.append(IOUtils.newStringFromBytes(lout.getRawBytes(), charsetName, 0, (int)limit)); } else if (currentStream instanceof ByteArrayOutputStream) { byte[] bytes = ((ByteArrayOutputStream)currentStream).toByteArray(); out.append(IOUtils.newStringFromBytes(bytes, charsetName, 0, (int)limit)); } else { throw new IOException("Unknown format of currentStream"); try (InputStream fin = createInputStream(tempFile); Reader reader = new InputStreamReader(fin, charsetName)) { char[] bytes = new char[1024];
public int copyFrom(InputStream in) throws IOException { int count = 0; while (buffer != null) { int pos = buffer.size(); int i = in.read(buffer.getRawBytes(), pos, this.threshold - pos); if (i > 0) { buffer.setSize(pos + i); if (buffer.size() >= threshold) { thresholdReached(); unBuffer(); } count += i; } else { return count; } } if (cachingForRetransmission) { count += IOUtils.copy(in, wrappedStream); } else { count += outbuf.copy(in); } return count; }
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 InputStream getInputStream() throws IOException { flush(); if (inmem) { if (currentStream instanceof LoadingByteArrayOutputStream) { return ((LoadingByteArrayOutputStream) currentStream).createInputStream(); } else if (currentStream instanceof ByteArrayOutputStream) { return new ByteArrayInputStream(((ByteArrayOutputStream) currentStream).toByteArray()); } else { return null; } } try { InputStream fileInputStream = new TransferableFileInputStream(tempFile); streamList.add(fileInputStream); if (cipherTransformation != null) { fileInputStream = new CipherInputStream(fileInputStream, ciphers.getDecryptor()) { boolean closed; public void close() throws IOException { if (!closed) { super.close(); closed = true; } } }; } return fileInputStream; } catch (FileNotFoundException e) { throw new IOException("Cached file was deleted, " + e.toString()); } }
private void maybeDeleteTempFile(Object stream) { streamList.remove(stream); if (!inmem && tempFile != null && streamList.isEmpty() && allowDeleteOfFile) { if (currentStream != null) { try { currentStream.close(); postClose(); } catch (Exception e) { //ignore } } deleteTempFile(); currentStream = new LoadingByteArrayOutputStream(1024); inmem = true; } }
public CachedOutputStream(long threshold) { this.threshold = threshold; currentStream = new LoadingByteArrayOutputStream(2048); inmem = true; readBusProperties(); }
public AbstractThresholdOutputStream(int threshold) { this.threshold = threshold; if (threshold >= 0) { buffer = new LoadingByteArrayOutputStream(threshold + 1); } }
MultiPartDataSource(Message message, DataSource root) { atts = message.getAttachments().iterator(); String s = (String)message.get(Message.CONTENT_TYPE); boundary = findBoundary(s); start = findStart(s); if (!s.contains(boundary)) { s += "; boundary=\"" + boundary + "\""; } contentType = s; rootPart = root; try { writer = new OutputStreamWriter(bout, "ASCII"); writer.append("Content-Type: ").append(contentType).append("\r\n\r\n"); writer.flush(); current = bout.createInputStream(); } catch (Exception e) { //nothing } }
public int write(ByteBuffer src) throws IOException { int total = 0; if (buffer != null) { int pos = buffer.size(); int len = this.threshold - pos; if (len > src.remaining()) { len = src.remaining(); } src.get(buffer.getRawBytes(), pos, len); buffer.setSize(buffer.size() + len); total += len; if (buffer.size() >= threshold) { thresholdReached(); unBuffer(); } } if (cachingForRetransmission) { wrappedStream.write(src.array(), src.position(), src.remaining()); return src.remaining() + total; } return outbuf.write(src) + total; }
@Override public void thresholdNotReached() { if (chunking) { setFixedLengthStreamingMode(buffer.size()); } }
/** * Load the InputStream into memory and return a ByteArrayInputStream that * represents it. Closes the in stream. * * @param in * @throws IOException */ public static ByteArrayInputStream loadIntoBAIS(InputStream in) throws IOException { int i = in.available(); if (i < DEFAULT_BUFFER_SIZE) { i = DEFAULT_BUFFER_SIZE; } LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream(i); copy(in, bout); in.close(); return bout.createInputStream(); }