/** * Sends a serializable object. */ public void writeObject(Object o) throws IOException { ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(out); oos.writeObject(o); // don't close oss, which will close the underlying stream // no need to flush either, given the way oos is implemented }
public long writeHtmlTo(long start, Writer w) throws IOException { ConsoleAnnotationOutputStream<T> caw = new ConsoleAnnotationOutputStream<>( w, createAnnotator(Stapler.getCurrentRequest()), context, charset); long r = super.writeLogTo(start,caw); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Cipher sym = PASSING_ANNOTATOR.encrypt(); ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos,sym))); oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack oos.writeObject(caw.getConsoleAnnotator()); oos.close(); StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp!=null) rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); return r; }
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; }
@Override public final void write(Command cmd, boolean last) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(baos); cmd.writeTo(channel,oos); oos.close(); byte[] block = baos.toByteArray(); channel.notifyWrite(cmd, block.length); writeBlock(channel, block); }
@Override public void write(Command cmd, boolean last) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(baos); cmd.writeTo(channel,oos); oos.close(); byte[] block = baos.toByteArray(); channel.notifyWrite(cmd, block.length); writeBlock(channel, block); } }
private byte[] _serialize(Object o, final Channel channel) throws IOException { Channel old = Channel.setCurrent(channel); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos; if (channel.remoteCapability.supportsMultiClassLoaderRPC()) oos = new MultiClassLoaderSerializer.Output(channel,baos); else oos = AnonymousClassWarnings.checkingObjectOutputStream(baos); oos.writeObject(o); return baos.toByteArray(); } finally { Channel.setCurrent(old); } }
/** * {@inheritDoc} */ @Override public void start() throws IOException { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(BinarySafeStream.wrap(bos)); try { oos.writeObject(new Capability()); } finally { oos.close(); } ByteBuffer buffer = ByteBufferUtils.wrapUTF8(bos.toString("US-ASCII")); write(buffer); } catch (IOException e) { futureChannel.setException(e); } }
/** * {@inheritDoc} */ @Override public final void write(Command cmd, boolean last) throws IOException { ByteBufferQueueOutputStream bqos = new ByteBufferQueueOutputStream(sendStaging); ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(bqos); try { cmd.writeTo(channel, oos); } finally { oos.close(); } long remaining = sendStaging.remaining(); channel.notifyWrite(cmd, remaining); while (remaining > 0L) { int frame = remaining > transportFrameSize ? transportFrameSize : (int) remaining; // # of bytes we send in this chunk writeChunkHeader.clear(); ChunkHeader.write(writeChunkHeader, frame, remaining > transportFrameSize); writeChunkHeader.flip(); writeChunkBody.clear(); writeChunkBody.limit(frame); sendStaging.get(writeChunkBody); writeChunkBody.flip(); write(writeChunkHeader, writeChunkBody); remaining -= frame; } }
/** * Instantiate a transport. * * @param is * The negotiated input stream that hides * @param os * {@linkplain CommandTransport#getUnderlyingStream() the underlying stream}. * @param mode * The mode to create the transport in. * @param cap * Capabilities of the other side, as determined during the handshaking. */ protected CommandTransport makeTransport(InputStream is, OutputStream os, Mode mode, Capability cap) throws IOException { FlightRecorderInputStream fis = new FlightRecorderInputStream(is); if (cap.supportsChunking()) return new ChunkedCommandTransport(cap, mode.wrap(fis), mode.wrap(os), os); else { ObjectOutputStream oos = AnonymousClassWarnings.checkingObjectOutputStream(mode.wrap(os)); oos.flush(); // make sure that stream preamble is sent to the other end. avoids dead-lock return new ClassicCommandTransport( new ObjectInputStreamEx(mode.wrap(fis),getBaseLoader(),getClassFilter()), oos,fis,os,cap); } } }