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 1298D10AED for ; Thu, 17 Oct 2013 00:26:43 +0000 (UTC) Received: (qmail 27769 invoked by uid 500); 17 Oct 2013 00:26:42 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 27666 invoked by uid 500); 17 Oct 2013 00:26:42 -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 27650 invoked by uid 99); 17 Oct 2013 00:26:42 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Oct 2013 00:26:42 +0000 Date: Thu, 17 Oct 2013 00:26:42 +0000 (UTC) From: "Sebb (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (IO-400) IOUtils: add support for copying from large byte buffers 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-400?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Sebb resolved IO-400. --------------------- Resolution: Duplicate Fix Version/s: 2.5 > IOUtils: add support for copying from large byte buffers > -------------------------------------------------------- > > Key: IO-400 > URL: https://issues.apache.org/jira/browse/IO-400 > Project: Commons IO > Issue Type: New Feature > Reporter: Sebb > Fix For: 2.5 > > > Trying to write a large byte array to a FileOutputStream may cause OOME. > This is because such output requires the use of native code, and native code may need to copy the array in order to access it safely, see: > http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp1265 > It might therefore be useful to have a method which writes from the byte array in chunks. One can create a ByteArrayInputStream from the input, and then use one of the copy() methods, but that creates an unnecessary array buffer (albeit only 4k). > There are already write methods which copy byte[] to OutputStream and char[] to Writer. > Some or all of these could be converted to use chunked output, or there could be new methods to implement the chunking. > Here is a sample implementation of a stand-alone method: > {code} > public static void writeChunked(byte[] data, OutputStream output) throws IOException { > int bytes = data.length; > int offset = 0; > while(bytes > 0) { > int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE); > output.write(data, offset, chunk); > bytes -= chunk; > offset += chunk; > } > } > {code} -- This message was sent by Atlassian JIRA (v6.1#6144)