Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7A0779886 for ; Wed, 9 May 2012 17:49:09 +0000 (UTC) Received: (qmail 75029 invoked by uid 500); 9 May 2012 17:49:09 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 74988 invoked by uid 500); 9 May 2012 17:49:09 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 74977 invoked by uid 99); 9 May 2012 17:49:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 May 2012 17:49:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 May 2012 17:49:06 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 867F323888CD; Wed, 9 May 2012 17:48:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1336315 - /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java Date: Wed, 09 May 2012 17:48:45 -0000 To: commits@chemistry.apache.org From: fmui@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120509174845.867F323888CD@eris.apache.org> Author: fmui Date: Wed May 9 17:48:45 2012 New Revision: 1336315 URL: http://svn.apache.org/viewvc?rev=1336315&view=rev Log: Server: more robust stream handling Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java?rev=1336315&r1=1336314&r2=1336315&view=diff ============================================================================== --- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java (original) +++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/shared/ThresholdOutputStream.java Wed May 9 17:48:45 2012 @@ -332,6 +332,7 @@ public class ThresholdOutputStream exten private class InternalTempFileInputStream extends FilterInputStream implements ThresholdInputStream { private boolean isDeleted = false; + private boolean isClosed = false; public InternalTempFileInputStream() throws FileNotFoundException { super(new BufferedInputStream(new FileInputStream(tempFile), memoryThreshold)); @@ -356,10 +357,18 @@ public class ThresholdOutputStream exten @Override public int read() throws IOException { + if (isClosed) { + return -1; + } + int b = super.read(); if (b == -1 && !isDeleted) { - super.close(); + try { + super.close(); + isClosed = true; + } catch (Exception e) { + } isDeleted = tempFile.delete(); } @@ -373,10 +382,18 @@ public class ThresholdOutputStream exten @Override public int read(byte[] b, int off, int len) throws IOException { + if (isClosed) { + return -1; + } + int n = super.read(b, off, len); if (n == -1 && !isDeleted) { - super.close(); + try { + super.close(); + isClosed = true; + } catch (Exception e) { + } isDeleted = tempFile.delete(); } @@ -385,8 +402,15 @@ public class ThresholdOutputStream exten @Override public void close() throws IOException { + if (!isClosed) { + try { + super.close(); + isClosed = true; + } catch (Exception e) { + } + } + if (!isDeleted) { - super.close(); isDeleted = tempFile.delete(); } }