Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 195881 Details for
Bug 346104
[Performance] ResourceUtil read and write methods should use buffers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch for readText
clipboard.txt (text/plain), 3.56 KB, created by
Ralf Sternberg
on 2011-05-17 11:38:31 EDT
(
hide
)
Description:
Patch for readText
Filename:
MIME Type:
Creator:
Ralf Sternberg
Created:
2011-05-17 11:38:31 EDT
Size:
3.56 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.rap.rwt >Index: src/org/eclipse/rwt/internal/resources/ResourceUtil.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt/org.eclipse.rap.rwt/src/org/eclipse/rwt/internal/resources/ResourceUtil.java,v >retrieving revision 1.14 >diff -u -r1.14 ResourceUtil.java >--- src/org/eclipse/rwt/internal/resources/ResourceUtil.java 9 May 2011 09:07:19 -0000 1.14 >+++ src/org/eclipse/rwt/internal/resources/ResourceUtil.java 17 May 2011 15:37:21 -0000 >@@ -88,21 +88,22 @@ > } > > static int[] readText( InputStream is, String charset, boolean compress ) throws IOException { >- StringBuffer buffer = new StringBuffer(); >+ StringBuffer text = new StringBuffer(); > InputStreamReader reader = new InputStreamReader( is, charset ); > BufferedReader br = new BufferedReader( reader ); >+ char[] buffer = new char[ 8096 ]; > try { >- int character = br.read(); >- while( character != -1 ) { >- buffer.append( ( char )character ); >- character = br.read(); >+ int readChars = br.read( buffer ); >+ while( readChars != -1 ) { >+ text.append( buffer, 0, readChars ); >+ readChars = br.read( buffer ); > } > } finally { > br.close(); > } > // compress (JavaScript-) buffer if requested > if( compress ) { >- compress( buffer ); >+ compress( text ); > } > // write just read resource to byte array stream > byte[] bytes; >@@ -110,7 +111,7 @@ > try { > OutputStreamWriter osw = new OutputStreamWriter( baos, HTTP.CHARSET_UTF_8 ); > try { >- osw.write( buffer.toString() ); >+ osw.write( text.toString() ); > osw.flush(); > } finally { > osw.close(); >#P org.eclipse.rap.rwt.test >Index: src/org/eclipse/rwt/internal/resources/ResourceUtil_Test.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.rap/runtime.rwt.test/org.eclipse.rap.rwt.test/src/org/eclipse/rwt/internal/resources/ResourceUtil_Test.java,v >retrieving revision 1.9 >diff -u -r1.9 ResourceUtil_Test.java >--- src/org/eclipse/rwt/internal/resources/ResourceUtil_Test.java 12 Apr 2011 14:36:49 -0000 1.9 >+++ src/org/eclipse/rwt/internal/resources/ResourceUtil_Test.java 17 May 2011 15:37:22 -0000 >@@ -11,8 +11,7 @@ > ******************************************************************************/ > package org.eclipse.rwt.internal.resources; > >-import java.io.File; >-import java.io.IOException; >+import java.io.*; > > import junit.framework.TestCase; > >@@ -82,6 +81,30 @@ > assertEquals( "foo\nbar\n", result ); > } > >+ public void testReadText() throws IOException { >+ String input = createTestString( 10000 ); >+ InputStream inputStream = new ByteArrayInputStream( input.getBytes( "UTF-8" ) ); >+ int[] result = ResourceUtil.readText( inputStream, "UTF-8", false ); >+ byte[] bytes = toByteArray( result ); >+ assertEquals( input, new String( bytes ) ); >+ } >+ >+ private static byte[] toByteArray( int[] result ) { >+ byte[] bytes = new byte[ result.length ]; >+ for( int i = 0; i < bytes.length; i++ ) { >+ bytes[ i ] = ( byte )result[ i ]; >+ } >+ return bytes; >+ } >+ >+ private static String createTestString( int length ) { >+ StringBuffer buffer = new StringBuffer( length ); >+ for( int i = 0; i < length; i++ ) { >+ buffer.append( (char) ( 32 + ( i % 32 ) ) ); >+ } >+ return buffer.toString(); >+ } >+ > private static int[] getStringAsIntArray( String string ) { > byte[] bytes = string.getBytes(); > int[] content = new int[ bytes.length ];
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 346104
: 195881 |
195890