/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @exception IOException if an error occurs. */ protected void thresholdReached() throws IOException { FileOutputStream fos = new FileOutputStream(outputFile); memoryOutputStream.writeTo(fos); currentOutputStream = fos; memoryOutputStream = null; }
/** * Writes the data from this output stream to the specified output stream, * after it has been closed. * * @param out output stream to write to. * @throws IOException if this stream is not yet closed or an error occurs. */ public void writeTo(final OutputStream out) throws IOException { // we may only need to check if this is closed if we are working with a file // but we should force the habit of closing wether we are working with // a file or memory. if (!closed) { throw new IOException("Stream not closed"); } if (isInMemory()) { memoryOutputStream.writeTo(out); } else { try (FileInputStream fis = new FileInputStream(outputFile)) { IOUtils.copy(fis, out); } } } }
/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @throws IOException if an error occurs. */ @Override protected void thresholdReached() throws IOException { if (prefix != null) { outputFile = File.createTempFile(prefix, suffix, directory); } FileUtils.forceMkdirParent(outputFile); final FileOutputStream fos = new FileOutputStream(outputFile); try { memoryOutputStream.writeTo(fos); } catch (final IOException e){ fos.close(); throw e; } currentOutputStream = fos; memoryOutputStream = null; }
memoryOutputStream.writeTo(out);
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (OutputStream gzos = new GZIPOutputStream(buf); ObjectOutputStream oos = JenkinsJVM.isJenkinsJVM() ? AnonymousClassWarnings.checkingObjectOutputStream(gzos) : new ObjectOutputStream(gzos)) { oos.writeObject(this); } ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); try { buf2.write(PREAMBLE); if (JenkinsJVM.isJenkinsJVM()) { // else we are in another JVM and cannot sign; result will be ignored unless INSECURE byte[] mac = MAC.mac(buf.toByteArray()); dos.writeInt(- mac.length); // negative to differentiate from older form dos.write(mac); } dos.writeInt(buf.size()); buf.writeTo(dos); } finally { dos.close(); } buf2.write(POSTAMBLE); return buf2; }
ref.writeTo(baout1); final java.io.ByteArrayOutputStream ref1 = new java.io.ByteArrayOutputStream(); baout.writeTo(ref1); checkStreams(baout1, ref1);
public String produce(final OutputStream dataSink) throws Exception { /* * Note this is executed in a different thread */ payload.writeTo(dataSink); return null; } };
public String produce(final OutputStream dataSink) throws Exception { /* * Note this is executed in a different thread */ payload.writeTo(dataSink); return null; } };
/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @throws IOException if an error occurs. */ protected void thresholdReached() throws IOException { ByteArrayOutputStream totalStream = new ByteArrayOutputStream(); memoryOutputStream.writeTo(totalStream); currentOutputStream = totalStream; memoryOutputStream = null; }
/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @exception IOException * if an error occurs. */ @Override protected void thresholdReached() throws IOException { ByteArrayOutputStream totalStream=new ByteArrayOutputStream(); memoryOutputStream.writeTo(totalStream); currentOutputStream = totalStream; memoryOutputStream = null; }
/** * Switches the underlying output stream from a memory based stream to one * that is backed by disk. This is the point at which we realise that too * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * * @exception IOException if an error occurs. */ protected void thresholdReached() throws IOException { if (prefix != null) { outputFile = File.createTempFile(prefix, suffix, directory); } FileOutputStream fos = new FileOutputStream(outputFile); memoryOutputStream.writeTo(fos); currentOutputStream = fos; memoryOutputStream = null; }
/** * Switches the underlying output stream from a memory based stream to one that is backed by disk. This is the point * at which we realise that too much data is being written to keep in memory, so we elect to switch to disk-based * storage. * * @throws IOException if an error occurs. */ protected void thresholdReached() throws IOException { FileOutputStream fos = new FileOutputStream(getFile()); memoryOutputStream.writeTo(fos); currentOutputStream = fos; memoryOutputStream = null; }
/** * Switches the underlying output stream from a memory based stream to one that is backed by disk. This is the point * at which we realise that too much data is being written to keep in memory, so we elect to switch to disk-based * storage. * * @throws IOException if an error occurs. */ protected void thresholdReached() throws IOException { FileOutputStream fos = new FileOutputStream(getFile()); memoryOutputStream.writeTo(fos); currentOutputStream = fos; memoryOutputStream = null; }
protected static void writeNiFiPropertiesFile(ByteArrayOutputStream nifiPropertiesOutputStream, String destPath) throws IOException { final Path nifiPropertiesPath = Paths.get(destPath, "nifi.properties"); try (FileOutputStream nifiProperties = new FileOutputStream(nifiPropertiesPath.toString())) { nifiPropertiesOutputStream.writeTo(nifiProperties); } finally { if (nifiPropertiesOutputStream != null) { nifiPropertiesOutputStream.flush(); nifiPropertiesOutputStream.close(); } } }
private void commit(byte functionType) throws IOException { int length = baout.size() + 2; assert length < 256; OutputStream out = getOutputStreamForControlSequence(length); out.write(length); out.write(functionType); baout.writeTo(out); }
@Override public void proceed() { try { List<Pair<String, byte[]>> entryList = readZipEntries(src) .parallelStream() .map(this::transformClassBlob) .collect(Collectors.toList()); if (entryList.isEmpty()) return; try (OutputStream fileOut = Files.newOutputStream(dst)) { ByteArrayOutputStream buffer = zipEntries(entryList); buffer.writeTo(fileOut); } } catch (IOException e) { throw new RuntimeException("Reading jar entries failure", e); } }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf)); oos.writeObject(this); oos.close(); ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); buf2.write(PREAMBLE); dos.writeInt(buf.size()); buf.writeTo(dos); dos.close(); buf2.write(POSTAMBLE); return buf2; }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf)); oos.writeObject(this); oos.close(); ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); buf2.write(PREAMBLE); dos.writeInt(buf.size()); buf.writeTo(dos); dos.close(); buf2.write(POSTAMBLE); return buf2; }
private ByteArrayOutputStream encodeToBytes() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf)); oos.writeObject(this); oos.close(); ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2,true,-1,null)); buf2.write(PREAMBLE); dos.writeInt(buf.size()); buf.writeTo(dos); dos.close(); buf2.write(POSTAMBLE); return buf2; }
protected ByteArrayOutputStream compress(ByteArrayOutputStream raw) throws TransportException { ByteArrayOutputStream compressed = new ByteArrayOutputStream(); BZip2CompressorOutputStream bcos = null; try { bcos = new BZip2CompressorOutputStream(compressed); } catch (IOException e) { throw new TransportException("unable to open compressed stream", e); } try { raw.writeTo(bcos); bcos.flush(); } catch (IOException e) { throw new TransportException("unable to compress data", e); } finally { try { bcos.close(); } catch (IOException e) { } } return compressed; }