Code example for ByteArrayInputStream

Methods: close

0
    @Override 
    protected String format(String request) {
        String result = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try { 
            ByteArrayInputStream bis = new ByteArrayInputStream(request.getBytes());
            Document doc = new SAXBuilder().build(bis);
            bis.close();
            Format format = Format.getCompactFormat();
            // To not have the ? in the declaration interpreted as regular expressions. 
            format.setOmitDeclaration(true);
            XMLOutputter out = new XMLOutputter(format);
            out.output(doc, bos);
            result = new String(bos.toByteArray());
            bos.close();
        } catch (Exception e) {
            log.error(null, e);
        } 
        return result;
    }