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 0BCAC115FB for ; Sun, 13 Jul 2014 15:17:05 +0000 (UTC) Received: (qmail 51080 invoked by uid 500); 13 Jul 2014 15:17:04 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 50994 invoked by uid 500); 13 Jul 2014 15:17:04 -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 50983 invoked by uid 99); 13 Jul 2014 15:17:04 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 13 Jul 2014 15:17:04 +0000 Date: Sun, 13 Jul 2014 15:17:04 +0000 (UTC) From: "Mikhail Mazursky (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (LANG-993) Add zero copy write method to StrBuilder 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/LANG-993?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Mikhail Mazursky closed LANG-993. --------------------------------- > Add zero copy write method to StrBuilder > ---------------------------------------- > > Key: LANG-993 > URL: https://issues.apache.org/jira/browse/LANG-993 > Project: Commons Lang > Issue Type: Improvement > Components: lang.text.* > Affects Versions: 3.3.1 > Reporter: Mikhail Mazursky > Assignee: Benedikt Ritter > Fix For: 3.4 > > Attachments: LANG-993-994.patch, LANG-993.patch > > > Currently I have the following usecase: > {code} > StrBuilder builder = new StrBuilder(); > // add lots of stuff to builder > // in multiple invocations in several classes > // writer cannot be used directly > builder.append(...); > Writer writer = ....; > CharStreams.copy(builder.asReader(), writer); > {code} > [CharStreams|https://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/io/CharStreams.java#177] is a class from Guava lib that copies data between reader and writer using temporary buffer. > There is a problem with such approach - two additional copies are performed: > 1) data is copied from the StrBuilder in chunks into temporary buffer (CharBuffer) > 2) Writer.append(CharSequence) is called that is usually implemented as write(CharSequence.toString()) - i.e. it makes another copy of data and allocates an additional String object. > I want to avoid those copies by writing the internal buffer of the StrBuilder directly to the writer. Also it is potentially more efficient because it performs one I/O call instead of many. > So I propose to add the following methods: > {code} > public void writeTo(Writer writer) throws IOException { > writer.write(buffer, 0, size); > } > public void writeTo(StringBuilder builder) { > builder.append(buffer, 0, size); > } > public void writeTo(StringBuffer buffer) { > buffer.append(this.buffer, 0, size); > } > {code} > If there is interest I will provide patch (with JavaDocs and tests). -- This message was sent by Atlassian JIRA (v6.2#6252)