Example usage for org.xml.sax.helpers DefaultHandler getClass

List of usage examples for org.xml.sax.helpers DefaultHandler getClass

Introduction

In this page you can find the example usage for org.xml.sax.helpers DefaultHandler getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.java

/**
 * Parses an XML document from an input stream using a document handler.
 *
 * @param handler/*from ww  w  .  j  a  va  2s .c o m*/
 *            the handler for the XML document
 * @param inputStream
 *            an input stream containing the XML document to parse
 *
 * @throws IOException
 *             on error reading from the input stream (ie connection reset)
 * @throws AmazonClientException
 *             on error with malformed XML, etc
 */
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream) throws IOException {
    try {

        if (log.isDebugEnabled()) {
            log.debug("Parsing XML response document with handler: " + handler.getClass());
        }

        BufferedReader breader = new BufferedReader(
                new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(breader));

    } catch (IOException e) {
        throw e;

    } catch (Throwable t) {
        try {
            inputStream.close();
        } catch (IOException e) {
            if (log.isErrorEnabled()) {
                log.error("Unable to close response InputStream up after XML parse failure", e);
            }
        }
        throw new AmazonClientException("Failed to parse XML document with handler " + handler.getClass(), t);
    }
}

From source file:com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.java

protected InputStream sanitizeXmlDocument(DefaultHandler handler, InputStream inputStream) throws IOException {

    if (!sanitizeXmlDocument) {
        // No sanitizing will be performed, return the original input stream unchanged.
        return inputStream;
    } else {//from   www  . j av  a  2  s . c  o  m
        if (log.isDebugEnabled()) {
            log.debug("Sanitizing XML document destined for handler " + handler.getClass());
        }

        InputStream sanitizedInputStream = null;

        try {

            /*
             * Read object listing XML document from input stream provided into a
             * string buffer, so we can replace troublesome characters before
             * sending the document to the XML parser.
             */
            StringBuilder listingDocBuffer = new StringBuilder();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));

            char[] buf = new char[8192];
            int read = -1;
            while ((read = br.read(buf)) != -1) {
                listingDocBuffer.append(buf, 0, read);
            }
            br.close();

            /*
             * Replace any carriage return (\r) characters with explicit XML
             * character entities, to prevent the SAX parser from
             * misinterpreting 0x0D characters as 0x0A and being unable to
             * parse the XML.
             */
            String listingDoc = listingDocBuffer.toString().replaceAll("\r", "&#013;");

            sanitizedInputStream = new ByteArrayInputStream(listingDoc.getBytes(UTF8));

        } catch (IOException e) {
            throw e;

        } catch (Throwable t) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                    log.error("Unable to close response InputStream after failure sanitizing XML document", e);
                }
            }
            throw new AmazonClientException(
                    "Failed to sanitize XML document destined for handler " + handler.getClass(), t);
        }
        return sanitizedInputStream;
    }
}

From source file:cn.ctyun.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.java

/**
 * Parses an XML document from an input stream using a document handler.
 *
 * @param handler/*from   w  w  w .j a  v  a2  s.  c  o  m*/
 *            the handler for the XML document
 * @param inputStream
 *            an input stream containing the XML document to parse
 *
 * @throws AmazonClientException
 *             any parsing, IO or other exceptions are wrapped in an
 *             S3ServiceException.
 */
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream)
        throws AmazonClientException {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Parsing XML response document with handler: " + handler.getClass());
        }

        BufferedReader breader = new BufferedReader(
                new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(breader));
    } catch (Throwable t) {
        try {
            inputStream.close();
        } catch (IOException e) {
            if (log.isErrorEnabled()) {
                log.error("Unable to close response InputStream up after XML parse failure", e);
            }
        }
        throw new AmazonClientException("Failed to parse XML document with handler " + handler.getClass(), t);
    }
}

From source file:cn.ctyun.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.java

protected InputStream sanitizeXmlDocument(DefaultHandler handler, InputStream inputStream)
        throws AmazonClientException {
    if (!sanitizeXmlDocument) {
        // No sanitizing will be performed, return the original input stream unchanged.
        return inputStream;
    } else {/*w  w  w .j  av  a2  s  .co m*/
        if (log.isDebugEnabled()) {
            log.debug("Sanitizing XML document destined for handler " + handler.getClass());
        }

        InputStream sanitizedInputStream = null;

        try {
            /*
             * Read object listing XML document from input stream provided into a
             * string buffer, so we can replace troublesome characters before
             * sending the document to the XML parser.
             */
            StringBuilder listingDocBuffer = new StringBuilder();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));

            char[] buf = new char[8192];
            int read = -1;
            while ((read = br.read(buf)) != -1) {
                listingDocBuffer.append(buf, 0, read);
            }
            br.close();

            /*
             * Replace any carriage return (\r) characters with explicit XML
             * character entities, to prevent the SAX parser from
             * misinterpreting 0x0D characters as 0x0A and being unable to
             * parse the XML.
             */
            String listingDoc = listingDocBuffer.toString().replaceAll("\r", "&#013;");

            sanitizedInputStream = new ByteArrayInputStream(listingDoc.getBytes(Constants.DEFAULT_ENCODING));
        } catch (Throwable t) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                    log.error("Unable to close response InputStream after failure sanitizing XML document", e);
                }
            }
            throw new AmazonClientException(
                    "Failed to sanitize XML document destined for handler " + handler.getClass(), t);
        }
        return sanitizedInputStream;
    }
}

From source file:org.jets3t.service.impl.rest.CloudFrontXmlResponsesSaxParser.java

/**
 * Parses an XML document from an input stream using a document handler.
 *
 * @param handler     The handler for the XML document
 * @param inputStream An input stream containing the XML document to parse
 * @throws CloudFrontServiceException Any parsing, IO or other exceptions are wrapped in an S3ServiceException.
 *//*  w ww.  j a va2  s  .  c  o m*/
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream)
        throws CloudFrontServiceException {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Parsing XML response document with handler: " + handler.getClass());
        }
        BufferedReader breader = new BufferedReader(
                new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(breader));
    } catch (Exception t) {
        try {
            inputStream.close();
        } catch (IOException e) {
            if (log.isErrorEnabled()) {
                log.error("Unable to close response InputStream up after XML parse failure", e);
            }
        }
        throw new CloudFrontServiceException("Failed to parse XML document with handler " + handler.getClass(),
                t);
    }
}

From source file:org.jets3t.service.impl.rest.XmlResponsesSaxParser.java

/**
 * Parses an XML document from an input stream using a document handler.
 * @param handler/*from w w  w .  j  av a  2  s .  co  m*/
 *        the handler for the XML document
 * @param inputStream
 *        an input stream containing the XML document to parse
 * @throws ServiceException
 *        any parsing, IO or other exceptions are wrapped in an ServiceException.
 */
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream) throws ServiceException {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Parsing XML response document with handler: " + handler.getClass());
        }
        BufferedReader breader = new BufferedReader(
                new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(breader));
        inputStream.close();
    } catch (Throwable t) {
        try {
            inputStream.close();
        } catch (IOException e) {
            if (log.isErrorEnabled()) {
                log.error("Unable to close response InputStream up after XML parse failure", e);
            }
        }
        throw new ServiceException("Failed to parse XML document with handler " + handler.getClass(), t);
    }
}

From source file:org.jets3t.service.impl.rest.XmlResponsesSaxParser.java

protected InputStream sanitizeXmlDocument(DefaultHandler handler, InputStream inputStream)
        throws ServiceException {
    if (!properties.getBoolProperty("xmlparser.sanitize-listings", true)) {
        // No sanitizing will be performed, return the original input stream unchanged.
        return inputStream;
    } else {/*from   w  w w .  ja  v a  2 s .  c o m*/
        if (log.isDebugEnabled()) {
            log.debug("Sanitizing XML document destined for handler " + handler.getClass());
        }

        InputStream sanitizedInputStream = null;

        try {
            /* Read object listing XML document from input stream provided into a
             * string buffer, so we can replace troublesome characters before
             * sending the document to the XML parser.
             */
            StringBuilder listingDocBuffer = new StringBuilder();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));

            char[] buf = new char[8192];
            int read = -1;
            while ((read = br.read(buf)) != -1) {
                listingDocBuffer.append(buf, 0, read);
            }
            br.close();

            // Replace any carriage return (\r) characters with explicit XML
            // character entities, to prevent the SAX parser from
            // misinterpreting 0x0D characters as 0x0A.
            String listingDoc = listingDocBuffer.toString().replaceAll("\r", "&#013;");

            sanitizedInputStream = new ByteArrayInputStream(listingDoc.getBytes(Constants.DEFAULT_ENCODING));
        } catch (Throwable t) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                    log.error("Unable to close response InputStream after failure sanitizing XML document", e);
                }
            }
            throw new ServiceException(
                    "Failed to sanitize XML document destined for handler " + handler.getClass(), t);
        }
        return sanitizedInputStream;
    }
}

From source file:pt.lunacloud.services.storage.model.transform.XmlResponsesSaxParser.java

/**
 * Parses an XML document from an input stream using a document handler.
 * //from  w  w  w .j  ava2  s.  c om
 * @param handler
 *            the handler for the XML document
 * @param inputStream
 *            an input stream containing the XML document to parse
 * 
 * @throws LunacloudClientException
 *             any parsing, IO or other exceptions are wrapped in an
 *             S3ServiceException.
 */
protected void parseXmlInputStream(DefaultHandler handler, InputStream inputStream)
        throws LunacloudClientException {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Parsing XML response document with handler: " + handler.getClass());
        }

        BufferedReader breader = new BufferedReader(
                new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));
        xr.setContentHandler(handler);
        xr.setErrorHandler(handler);
        xr.parse(new InputSource(breader));
    } catch (Throwable t) {
        try {
            inputStream.close();
        } catch (IOException e) {
            if (log.isErrorEnabled()) {
                log.error("Unable to close response InputStream up after XML parse failure", e);
            }
        }
        throw new LunacloudClientException("Failed to parse XML document with handler " + handler.getClass(),
                t);
    }
}

From source file:pt.lunacloud.services.storage.model.transform.XmlResponsesSaxParser.java

protected InputStream sanitizeXmlDocument(DefaultHandler handler, InputStream inputStream)
        throws LunacloudClientException {
    if (!sanitizeXmlDocument) {
        // No sanitizing will be performed, return the original input stream
        // unchanged.
        return inputStream;
    } else {// w  ww . ja v  a 2  s.  co  m
        if (log.isDebugEnabled()) {
            log.debug("Sanitizing XML document destined for handler " + handler.getClass());
        }

        InputStream sanitizedInputStream = null;

        try {
            /*
             * Read object listing XML document from input stream provided
             * into a string buffer, so we can replace troublesome
             * characters before sending the document to the XML parser.
             */
            StringBuilder listingDocBuffer = new StringBuilder();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));

            char[] buf = new char[8192];
            int read = -1;
            while ((read = br.read(buf)) != -1) {
                listingDocBuffer.append(buf, 0, read);
            }
            br.close();

            /*
             * Replace any carriage return (\r) characters with explicit XML
             * character entities, to prevent the SAX parser from
             * misinterpreting 0x0D characters as 0x0A and being unable to
             * parse the XML.
             */
            String listingDoc = listingDocBuffer.toString().replaceAll("\r", "&#013;");

            sanitizedInputStream = new ByteArrayInputStream(listingDoc.getBytes(Constants.DEFAULT_ENCODING));
        } catch (Throwable t) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                    log.error("Unable to close response InputStream after failure sanitizing XML document", e);
                }
            }
            throw new LunacloudClientException(
                    "Failed to sanitize XML document destined for handler " + handler.getClass(), t);
        }
        return sanitizedInputStream;
    }
}

From source file:s3.com.qiniu.services.s3.model.transform.XmlResponsesSaxParser.java

protected InputStream sanitizeXmlDocument(DefaultHandler handler, InputStream inputStream) throws IOException {

    if (!sanitizeXmlDocument) {
        // No sanitizing will be performed, return the original input stream
        // unchanged.
        return inputStream;
    } else {/*  ww w  .  j  av a 2  s. c  om*/
        if (log.isDebugEnabled()) {
            log.debug("Sanitizing XML document destined for handler " + handler.getClass());
        }

        InputStream sanitizedInputStream = null;

        try {

            /*
             * Read object listing XML document from input stream provided
             * into a string buffer, so we can replace troublesome
             * characters before sending the document to the XML parser.
             */
            StringBuilder listingDocBuffer = new StringBuilder();
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(inputStream, Constants.DEFAULT_ENCODING));

            char[] buf = new char[8192];
            int read = -1;
            while ((read = br.read(buf)) != -1) {
                listingDocBuffer.append(buf, 0, read);
            }
            br.close();

            /*
             * Replace any carriage return (\r) characters with explicit XML
             * character entities, to prevent the SAX parser from
             * misinterpreting 0x0D characters as 0x0A and being unable to
             * parse the XML.
             */
            String listingDoc = listingDocBuffer.toString().replaceAll("\r", "&#013;");

            sanitizedInputStream = new ByteArrayInputStream(listingDoc.getBytes(UTF8));

        } catch (IOException e) {
            throw e;

        } catch (Throwable t) {
            try {
                inputStream.close();
            } catch (IOException e) {
                if (log.isErrorEnabled()) {
                    log.error("Unable to close response InputStream after failure sanitizing XML document", e);
                }
            }
            throw new AmazonClientException(
                    "Failed to sanitize XML document destined for handler " + handler.getClass(), t);
        }
        return sanitizedInputStream;
    }
}