Search in sources :

Example 1 with IOException2

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

the class AnnotatedLargeText method createAnnotator.

private ConsoleAnnotator createAnnotator(StaplerRequest req) throws IOException {
    try {
        String base64 = req != null ? req.getHeader("X-ConsoleAnnotator") : null;
        if (base64 != null) {
            Cipher sym = Secret.getCipher("AES");
            sym.init(Cipher.DECRYPT_MODE, Hudson.getInstance().getSecretKeyAsAES128());
            ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())), sym)), Hudson.getInstance().pluginManager.uberClassLoader);
            long timestamp = ois.readLong();
            if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis() - timestamp))
                // don't deserialize something too old to prevent a replay attack
                return (ConsoleAnnotator) ois.readObject();
        }
    } catch (GeneralSecurityException e) {
        throw new IOException2(e);
    } catch (ClassNotFoundException e) {
        throw new IOException2(e);
    }
    // start from scratch
    return ConsoleAnnotator.initial(context == null ? null : context.getClass());
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) CipherInputStream(javax.crypto.CipherInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GeneralSecurityException(java.security.GeneralSecurityException) Cipher(javax.crypto.Cipher) ObjectInputStreamEx(hudson.remoting.ObjectInputStreamEx) IOException2(hudson.util.IOException2) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with IOException2

use of hudson.util.IOException2 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 3 with IOException2

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

the class TarArchiver method visitSymlink.

@Override
public void visitSymlink(File link, String target, String relativePath) throws IOException {
    TarEntry e = new TarEntry(relativePath, LF_SYMLINK);
    try {
        StringBuffer linkName = (StringBuffer) LINKNAME_FIELD.get(e);
        linkName.setLength(0);
        linkName.append(target);
    } catch (IllegalAccessException x) {
        throw new IOException2("Failed to set linkName", x);
    }
    tar.putNextEntry(e);
    entriesWritten++;
}
Also used : TarEntry(org.apache.tools.tar.TarEntry) IOException2(hudson.util.IOException2)

Example 4 with IOException2

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

the class SFTPClient method mkdirs.

/**
 * Makes sure that the directory exists, by creating it if necessary.
 */
public void mkdirs(String path, int posixPermission) throws IOException {
    SFTPv3FileAttributes atts = _stat(path);
    if (atts != null && atts.isDirectory())
        return;
    int idx = path.lastIndexOf("/");
    if (idx > 0)
        mkdirs(path.substring(0, idx), posixPermission);
    try {
        mkdir(path, posixPermission);
    } catch (IOException e) {
        throw new IOException2("Failed to mkdir " + path, e);
    }
}
Also used : IOException(java.io.IOException) SFTPv3FileAttributes(com.trilead.ssh2.SFTPv3FileAttributes) IOException2(hudson.util.IOException2)

Example 5 with IOException2

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

the class XmlFile method write.

public void write(Object o) throws IOException {
    mkdirs();
    AtomicFileWriter w = new AtomicFileWriter(file);
    try {
        w.write("<?xml version='1.0' encoding='UTF-8'?>\n");
        xs.toXML(o, w);
        w.commit();
    } catch (StreamException e) {
        throw new IOException2(e);
    } finally {
        w.abort();
    }
}
Also used : AtomicFileWriter(hudson.util.AtomicFileWriter) IOException2(hudson.util.IOException2) StreamException(com.thoughtworks.xstream.io.StreamException)

Aggregations

IOException2 (hudson.util.IOException2)36 IOException (java.io.IOException)19 File (java.io.File)16 FileInputStream (java.io.FileInputStream)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 InputStream (java.io.InputStream)4 ObjectInputStream (java.io.ObjectInputStream)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 TarInputStream (hudson.org.apache.tools.tar.TarInputStream)3 VirtualChannel (hudson.remoting.VirtualChannel)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 SAXException (org.xml.sax.SAXException)3 XmlPullParser (org.xmlpull.v1.XmlPullParser)3 XmlPullParserFactory (org.xmlpull.v1.XmlPullParserFactory)3 StreamException (com.thoughtworks.xstream.io.StreamException)2 ObjectInputStreamEx (hudson.remoting.ObjectInputStreamEx)2