camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-2551) File component does not correctly handle PipedInputStream in message body.
Date Tue, 16 Mar 2010 05:03:45 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-2551?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=58259#action_58259
] 

Claus Ibsen commented on CAMEL-2551:
------------------------------------

Sergey well spotted.

Btw which use case do you use a PipedInputStream with?

> File component does not correctly handle PipedInputStream in message body.
> --------------------------------------------------------------------------
>
>                 Key: CAMEL-2551
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-2551
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 2.2.0
>         Environment: does not matter
>            Reporter: Sergey Zolotaryov
>            Assignee: Willem Jiang
>         Attachments: patch.txt
>
>
> Streams that do not have their contents length at immediate disposal, like PipedInputStream,
are not processed correctly by the file component.
> \\
> {code}
>     private void writeFileByStream(InputStream in, File target) throws IOException {
>         FileChannel out = null;
>         try {
>             out = prepareOutputFileChannel(target, out);
>             if (LOG.isTraceEnabled()) {
>                 LOG.trace("Using InputStream to transfer from: " + in + " to: " + out);
>             }
>             int size = endpoint.getBufferSize();
>             byte[] buffer = new byte[size];
>             ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
>             while (true) {
>                 int count = in.read(buffer);
>                 if (count <= 0) {
>                     break;
>                 } else if (count < size) {
>                     byteBuffer = ByteBuffer.wrap(buffer, 0, count);
>                     out.write(byteBuffer);
>                     break;
>                 } else {
>                     out.write(byteBuffer);
>                     byteBuffer.clear();
>                 }
>             }
>         } finally {
>             ObjectHelper.close(in, target.getName(), LOG);
>             ObjectHelper.close(out, target.getName(), LOG);
>         }
>     }
> {code}
> The code 
> {code}
>                 } else if (count < size) {
>                     byteBuffer = ByteBuffer.wrap(buffer, 0, count);
>                     out.write(byteBuffer);
>                     break;
>                 } else {
> {code}
> does not take into account that bytes read can be less than the size of the buffer passed
into the InputStream.read method and stream can still have more content. The only indication
that EOF was reached is -1 returned from the read method according to Java API.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message