Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 346104 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/rwt/internal/resources/ResourceUtil.java (-7 / +8 lines)
Lines 88-108 Link Here
88
  }
88
  }
89
89
90
  static int[] readText( InputStream is, String charset, boolean compress ) throws IOException {
90
  static int[] readText( InputStream is, String charset, boolean compress ) throws IOException {
91
    StringBuffer buffer = new StringBuffer();
91
    StringBuffer text = new StringBuffer();
92
    InputStreamReader reader = new InputStreamReader( is, charset );
92
    InputStreamReader reader = new InputStreamReader( is, charset );
93
    BufferedReader br = new BufferedReader( reader );
93
    BufferedReader br = new BufferedReader( reader );
94
    char[] buffer = new char[ 8096 ];
94
    try {
95
    try {
95
      int character = br.read();
96
      int readChars = br.read( buffer );
96
      while( character != -1 ) {
97
      while( readChars != -1 ) {
97
        buffer.append( ( char )character );
98
        text.append( buffer, 0, readChars );
98
        character = br.read();
99
        readChars = br.read( buffer );
99
      }
100
      }
100
    } finally {
101
    } finally {
101
      br.close();
102
      br.close();
102
    }
103
    }
103
    // compress (JavaScript-) buffer if requested
104
    // compress (JavaScript-) buffer if requested
104
    if( compress ) {
105
    if( compress ) {
105
      compress( buffer );
106
      compress( text );
106
    }
107
    }
107
    // write just read resource to byte array stream
108
    // write just read resource to byte array stream
108
    byte[] bytes;
109
    byte[] bytes;
Lines 110-116 Link Here
110
    try {
111
    try {
111
      OutputStreamWriter osw = new OutputStreamWriter( baos, HTTP.CHARSET_UTF_8 );
112
      OutputStreamWriter osw = new OutputStreamWriter( baos, HTTP.CHARSET_UTF_8 );
112
      try {
113
      try {
113
        osw.write( buffer.toString() );
114
        osw.write( text.toString() );
114
        osw.flush();
115
        osw.flush();
115
      } finally {
116
      } finally {
116
        osw.close();
117
        osw.close();
(-)src/org/eclipse/rwt/internal/resources/ResourceUtil_Test.java (-2 / +25 lines)
Lines 11-18 Link Here
11
 ******************************************************************************/
11
 ******************************************************************************/
12
package org.eclipse.rwt.internal.resources;
12
package org.eclipse.rwt.internal.resources;
13
13
14
import java.io.File;
14
import java.io.*;
15
import java.io.IOException;
16
15
17
import junit.framework.TestCase;
16
import junit.framework.TestCase;
18
17
Lines 82-87 Link Here
82
    assertEquals( "foo\nbar\n", result );
81
    assertEquals( "foo\nbar\n", result );
83
  }
82
  }
84
83
84
  public void testReadText() throws IOException {
85
    String input = createTestString( 10000 );
86
    InputStream inputStream = new ByteArrayInputStream( input.getBytes( "UTF-8" ) );
87
    int[] result = ResourceUtil.readText( inputStream, "UTF-8", false );
88
    byte[] bytes = toByteArray( result );
89
    assertEquals( input, new String( bytes ) );
90
  }
91
92
  private static byte[] toByteArray( int[] result ) {
93
    byte[] bytes = new byte[ result.length ];
94
    for( int i = 0; i < bytes.length; i++ ) {
95
      bytes[ i ] = ( byte )result[ i ];
96
    }
97
    return bytes;
98
  }
99
100
  private static String createTestString( int length ) {
101
    StringBuffer buffer = new StringBuffer( length );
102
    for( int i = 0; i < length; i++ ) {
103
      buffer.append( (char) ( 32 + ( i % 32 ) ) );
104
    }
105
    return buffer.toString();
106
  }
107
85
  private static int[] getStringAsIntArray( String string ) {
108
  private static int[] getStringAsIntArray( String string ) {
86
    byte[] bytes = string.getBytes();
109
    byte[] bytes = string.getBytes();
87
    int[] content = new int[ bytes.length ];
110
    int[] content = new int[ bytes.length ];

Return to bug 346104