Search in sources :

Example 1 with UnbufferedBase64InputStream

use of hudson.util.UnbufferedBase64InputStream in project hudson-2.x by hudson.

the class ConsoleNote method readFrom.

/**
     * Reads a note back from {@linkplain #encodeTo(OutputStream) its encoded form}.
     *
     * @param in
     *      Must point to the beginning of a preamble.
     *
     * @return null if the encoded form is malformed.
     */
public static ConsoleNote readFrom(DataInputStream in) throws IOException, ClassNotFoundException {
    try {
        byte[] preamble = new byte[PREAMBLE.length];
        in.readFully(preamble);
        if (!Arrays.equals(preamble, PREAMBLE))
            // not a valid preamble
            return null;
        DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in));
        int sz = decoded.readInt();
        //Size should be greater than Zero. See http://issues.hudson-ci.org/browse/HUDSON-6558
        if (sz < 0) {
            return null;
        }
        byte[] buf = new byte[sz];
        decoded.readFully(buf);
        byte[] postamble = new byte[POSTAMBLE.length];
        in.readFully(postamble);
        if (!Arrays.equals(postamble, POSTAMBLE))
            // not a valid postamble
            return null;
        ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new ByteArrayInputStream(buf)), Hudson.getInstance().pluginManager.uberClassLoader);
        return (ConsoleNote) ois.readObject();
    } catch (Error e) {
        // package that up as IOException so that the caller won't fatally die.
        throw new IOException2(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) UnbufferedBase64InputStream(hudson.util.UnbufferedBase64InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStreamEx(hudson.remoting.ObjectInputStreamEx) DataInputStream(java.io.DataInputStream) IOException2(hudson.util.IOException2) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with UnbufferedBase64InputStream

use of hudson.util.UnbufferedBase64InputStream in project hudson-2.x by hudson.

the class ConsoleNote method skip.

/**
     * Skips the encoded console note.
     */
public static void skip(DataInputStream in) throws IOException {
    byte[] preamble = new byte[PREAMBLE.length];
    in.readFully(preamble);
    if (!Arrays.equals(preamble, PREAMBLE))
        // not a valid preamble
        return;
    DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in));
    int sz = decoded.readInt();
    IOUtils.skip(decoded, sz);
    byte[] postamble = new byte[POSTAMBLE.length];
    in.readFully(postamble);
}
Also used : UnbufferedBase64InputStream(hudson.util.UnbufferedBase64InputStream) DataInputStream(java.io.DataInputStream)

Aggregations

UnbufferedBase64InputStream (hudson.util.UnbufferedBase64InputStream)2 DataInputStream (java.io.DataInputStream)2 ObjectInputStreamEx (hudson.remoting.ObjectInputStreamEx)1 IOException2 (hudson.util.IOException2)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1