Example usage for java.util.zip DataFormatException getClass

List of usage examples for java.util.zip DataFormatException getClass

Introduction

In this page you can find the example usage for java.util.zip DataFormatException getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static String getBlobAsString(Blob blob, String column, String charset, boolean xmlEncode,
        boolean blobIsCompressed, boolean blobSmartGet, boolean encodeBlobBase64)
        throws IOException, JdbcException, SQLException, JMSException {
    if (encodeBlobBase64) {
        InputStream blobStream = JdbcUtil.getBlobInputStream(blob, column, blobIsCompressed);
        return Misc.streamToString(new Base64InputStream(blobStream, true), null, false);
    }/*  w  w  w  .  j  av a  2  s.c om*/
    if (blobSmartGet) {
        if (blob == null) {
            log.debug("no blob found in column [" + column + "]");
            return null;
        }
        int bl = (int) blob.length();

        InputStream is = blob.getBinaryStream();
        byte[] buf = new byte[bl];
        int bl1 = is.read(buf);

        Inflater decompressor = new Inflater();
        decompressor.setInput(buf);
        ByteArrayOutputStream bos = new ByteArrayOutputStream(buf.length);
        byte[] bufDecomp = new byte[1024];
        boolean decompresOK = true;
        while (!decompressor.finished()) {
            try {
                int count = decompressor.inflate(bufDecomp);
                if (count == 0) {
                    break;
                }
                bos.write(bufDecomp, 0, count);
            } catch (DataFormatException e) {
                log.debug("message in column [" + column + "] is not compressed");
                decompresOK = false;
                break;
            }
        }
        bos.close();
        if (decompresOK)
            buf = bos.toByteArray();

        Object result = null;
        ObjectInputStream ois = null;
        boolean objectOK = true;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(buf);
            ois = new ObjectInputStream(bis);
            result = ois.readObject();
        } catch (Exception e) {
            log.debug("message in column [" + column + "] is probably not a serialized object: "
                    + e.getClass().getName());
            objectOK = false;
        }
        if (ois != null)
            ois.close();

        String rawMessage;
        if (objectOK) {
            if (result instanceof IMessageWrapper) {
                rawMessage = ((IMessageWrapper) result).getText();
            } else if (result instanceof TextMessage) {
                rawMessage = ((TextMessage) result).getText();
            } else {
                rawMessage = (String) result;
            }
        } else {
            rawMessage = new String(buf, charset);
        }

        String message = XmlUtils.encodeCdataString(rawMessage);
        return message;
    }
    return Misc.readerToString(getBlobReader(blob, column, charset, blobIsCompressed), null, xmlEncode);
}

From source file:org.barcelonamedia.uima.reader.DBXMIReader.DBXMICollectionReader.java

public void getNext(CAS aCAS) throws IOException, CollectionException {

    try {//  ww  w  .j a v  a  2s.  co  m

        if (this.do_decompression) {

            //Create the decompressor and give it the data to compress
            Inflater decompressor = new Inflater();
            byte[] documentDataByteArray = IOUtils.toByteArray(this.documentData);

            decompressor.setInput(documentDataByteArray);

            //Create an expandable byte array to hold the decompressed data
            ByteArrayOutputStream bos = new ByteArrayOutputStream(documentDataByteArray.length);

            //Decompress the data
            byte[] buf = new byte[1024];

            while (!decompressor.finished()) {

                try {

                    int count = decompressor.inflate(buf);
                    bos.write(buf, 0, count);
                } catch (DataFormatException e) {

                    System.err.println("ERROR in Collection Reader " + e.getClass() + ": " + e.getMessage());
                    throw new IOException();
                }
            }

            try {

                bos.close();
            } catch (IOException e) {

                System.err.println("ERROR in Collection Reader " + e.getClass() + ": " + e.getMessage());
                throw new IOException();
            }

            //Get the decompressed data
            byte[] decompressedData = bos.toByteArray();

            XmiCasDeserializer.deserialize(new ByteArrayInputStream(decompressedData), aCAS,
                    !this.mFailOnUnknownType);
        } else {

            XmiCasDeserializer.deserialize(this.documentData, aCAS, !this.mFailOnUnknownType);
        }

        this.currentIndex += 1;
    } catch (SAXException e) {

        System.err.println("ERROR in Collection Reader " + e.getClass() + ": " + e.getMessage());
        throw new CollectionException(e);
    }
}