Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EA5F810E1A for ; Tue, 23 Jul 2013 03:50:50 +0000 (UTC) Received: (qmail 97118 invoked by uid 500); 23 Jul 2013 03:50:50 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 97054 invoked by uid 500); 23 Jul 2013 03:50:50 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 97022 invoked by uid 99); 23 Jul 2013 03:50:49 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Jul 2013 03:50:49 +0000 Date: Tue, 23 Jul 2013 03:50:48 +0000 (UTC) From: "BELUGA BEHR (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (IO-391) DeferredFileInputStream MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/IO-391?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] BELUGA BEHR updated IO-391: --------------------------- Attachment: (was: DeferredFileInputStreamTest.java) > DeferredFileInputStream > ----------------------- > > Key: IO-391 > URL: https://issues.apache.org/jira/browse/IO-391 > Project: Commons IO > Issue Type: Wish > Components: Streams/Writers > Reporter: BELUGA BEHR > Priority: Minor > Attachments: DeferredFileInputStream.java, DeferredFileInputStreamTest.java > > > I have included an implementation of a "DeferredFileInputStream". It wraps a Java Util FileInputStream, but it opens a file handle when it's absolutely required. This goes well with DeferredFileOutputStream. What I like to do is... > {code} > InputStream is = null; > DeferredFileOutputStream dfos = new DeferredFileOutputStream(1024, file); > // InputStream opened earlier > IoUtils.copy(in, dfos); > if (dfos.ifIsInMemory()) > { > is = new ByteInputStream(dfos.getData()); > } > else > { > is = new DeferredFileInputStream(dfos.getFile()); > } > IoUtils.closeQuietly(dfos); > return is; > {code} > That way, I can generate a large list of InputStreams (for a a batch job as an example) and queue them up for different threads to take without creating lots of file handles. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira