Examples of ThresholdOutputStream


Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

                } else {
                    filename = item.getName();
                    contentType = (item.getContentType() == null ? Constants.MEDIATYPE_OCTETSTREAM : item
                            .getContentType());

                    ThresholdOutputStream os = new ThresholdOutputStream(tempDir, memoryThreshold);

                    try {
                        byte[] buffer = new byte[64 * 1024];
                        int b = 0;
                        while ((b = itemStream.read(buffer)) > -1) {
                            os.write(buffer, 0, b);
                        }

                        os.close();

                        size = BigInteger.valueOf(os.getSize());
                        stream = os.getInputStream();
                    } catch (Exception e) {
                        // if something went wrong, make sure the temp file will
                        // be deleted
                        os.destroy();
                        throw e;
                    } finally {
                        try {
                            itemStream.close();
                        } catch (Exception e) {
View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

        } else if (type.endsWith("/xml") || type.endsWith("+xml")) {
            bytes = copy(parser);
        } else if (type.startsWith("text/")) {
            bytes = readText(parser).getBytes("UTF-8");
        } else {
            ThresholdOutputStream ths = readBase64(parser);
            atomContentStream.setStream(ths.getInputStream());
            atomContentStream.setLength(BigInteger.valueOf(ths.getSize()));
        }

        if (bytes != null) {
            atomContentStream.setStream(new ByteArrayInputStream(bytes));
            atomContentStream.setLength(BigInteger.valueOf(bytes.length));
View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

                if (Constants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
                    if (TAG_MEDIATYPE.equals(name.getLocalPart())) {
                        cmisContentStream.setMimeType(readText(parser));
                    } else if (TAG_BASE64.equals(name.getLocalPart())) {
                        ThresholdOutputStream ths = readBase64(parser);
                        cmisContentStream.setStream(ths.getInputStream());
                        cmisContentStream.setLength(BigInteger.valueOf(ths.getSize()));
                    } else {
                        skip(parser);
                    }
                } else {
                    skip(parser);
View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

    /**
     * Parses a tag that contains base64 encoded content.
     */
    private ThresholdOutputStream readBase64(XMLStreamReader parser) throws Exception {
        ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold);
        Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream, Base64.DECODE);

        next(parser);

        try {
            while (true) {
                int event = parser.getEventType();
                if (event == XMLStreamReader.END_ELEMENT) {
                    break;
                } else if (event == XMLStreamReader.CHARACTERS) {
                    String s = parser.getText();
                    if (s != null) {
                        b64stream.write(s.getBytes("US-ASCII"));
                    }
                } else if (event == XMLStreamReader.START_ELEMENT) {
                    throw new RuntimeException("Unexpected tag: " + parser.getName());
                }

                if (!next(parser)) {
                    break;
                }
            }

            b64stream.close();
        } catch (Exception e) {
            bufferStream.destroy(); // remove temp file
            throw e;
        }

        next(parser);

View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

        } else if (type.endsWith("/xml") || type.endsWith("+xml")) {
            bytes = copy(parser);
        } else if (type.startsWith("text/")) {
            bytes = readText(parser).getBytes("UTF-8");
        } else {
            ThresholdOutputStream ths = readBase64(parser);
            atomContentStream.setStream(ths.getInputStream());
            atomContentStream.setLength(BigInteger.valueOf(ths.getSize()));
        }

        if (bytes != null) {
            atomContentStream.setStream(new ByteArrayInputStream(bytes));
            atomContentStream.setLength(BigInteger.valueOf(bytes.length));
View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

                if (Constants.NAMESPACE_RESTATOM.equals(name.getNamespaceURI())) {
                    if (TAG_MEDIATYPE.equals(name.getLocalPart())) {
                        cmisContentStream.setMimeType(readText(parser));
                    } else if (TAG_BASE64.equals(name.getLocalPart())) {
                        ThresholdOutputStream ths = readBase64(parser);
                        cmisContentStream.setStream(ths.getInputStream());
                        cmisContentStream.setLength(BigInteger.valueOf(ths.getSize()));
                    } else {
                        skip(parser);
                    }
                } else if (Constants.NAMESPACE_APACHE_CHEMISTRY.equals(name.getNamespaceURI())) {
                    if (TAG_FILENAME.equals(name.getLocalPart())) {
View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

    /**
     * Parses a tag that contains base64 encoded content.
     */
    private ThresholdOutputStream readBase64(XMLStreamReader parser) throws Exception {
        ThresholdOutputStream bufferStream = new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize,
                encrypt);
        @SuppressWarnings("resource")
        Base64.OutputStream b64stream = new Base64.OutputStream(bufferStream, Base64.DECODE);

        next(parser);

        try {
            while (true) {
                int event = parser.getEventType();
                if (event == XMLStreamReader.END_ELEMENT) {
                    break;
                } else if (event == XMLStreamReader.CHARACTERS) {
                    String s = parser.getText();
                    if (s != null) {
                        b64stream.write(s.getBytes("US-ASCII"));
                    }
                } else if (event == XMLStreamReader.START_ELEMENT) {
                    throw new RuntimeException("Unexpected tag: " + parser.getName());
                }

                if (!next(parser)) {
                    break;
                }
            }

            b64stream.close();
        } catch (Exception e) {
            bufferStream.destroy(); // remove temp file
            throw e;
        }

        next(parser);

View Full Code Here

Examples of org.apache.chemistry.opencmis.server.shared.ThresholdOutputStream

            throw new CmisInvalidArgumentException("Limit exceeded!");
        }
    }

    private void readBodyAsStream() throws IOException {
        ThresholdOutputStream stream = new ThresholdOutputStream(tempDir, memoryThreshold, maxContentSize, encrypt);

        try {
            while (true) {
                readBuffer();

                int boundaryPosition = findBoundary();

                if (boundaryPosition > -1) {
                    stream.write(buffer, bufferPosition, boundaryPosition - bufferPosition);
                    bufferPosition = boundaryPosition + boundary.length;
                    break;
                } else {
                    int len = Math.min(BUFFER_SIZE, bufferCount) - bufferPosition;
                    stream.write(buffer, bufferPosition, len);
                    bufferPosition = bufferPosition + len;
                }
            }

            stream.close();

            contentSize = BigInteger.valueOf(stream.getSize());
            contentStream = stream.getInputStream();
        } catch (IOException e) {
            // if something went wrong, make sure the temp file will
            // be deleted
            stream.destroy();
            throw e;
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.