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/JSLibraryConcatenator.java (-3 / +3 lines)
Lines 64-70 Link Here
64
    jsConcatenator = new ByteArrayOutputStream();
64
    jsConcatenator = new ByteArrayOutputStream();
65
  }
65
  }
66
66
67
  public void appendJSLibrary( File toWrite, int[] content ) {
67
  public void appendJSLibrary( File toWrite, byte[] content ) {
68
    if( isAllowed( toWrite ) ) {
68
    if( isAllowed( toWrite ) ) {
69
      for( int i = 0; i < content.length; i++ ) {
69
      for( int i = 0; i < content.length; i++ ) {
70
        jsConcatenator.write( content[ i ] );
70
        jsConcatenator.write( content[ i ] );
Lines 97-104 Link Here
97
    jsConcatenator.write( '\n' );
97
    jsConcatenator.write( '\n' );
98
  }
98
  }
99
99
100
  private boolean isLastCharacter( int[] content, int i ) {
100
  private static boolean isLastCharacter( byte[] content, int position ) {
101
    return i == content.length - 1;
101
    return position == content.length - 1;
102
  }
102
  }
103
103
104
  private void initialize() throws UnsupportedEncodingException, IOException {
104
  private void initialize() throws UnsupportedEncodingException, IOException {
(-)src/org/eclipse/rwt/internal/resources/ResourceManagerImpl.java (-10 / +10 lines)
Lines 79-92 Link Here
79
79
80
    /** the 'raw' content of the resource. In case of a text resource (charset
80
    /** the 'raw' content of the resource. In case of a text resource (charset
81
     * was given) the content is UTF-8 encoded. */
81
     * was given) the content is UTF-8 encoded. */
82
    private final int[] content;
82
    private final byte[] content;
83
    /** the charset in which the resource was encoded before read or null for
83
    /** the charset in which the resource was encoded before read or null for
84
     * binary resources. */
84
     * binary resources. */
85
    private final String charset;
85
    private final String charset;
86
    /** the resource's version or null for 'no version' */
86
    /** the resource's version or null for 'no version' */
87
    private final Integer version;
87
    private final Integer version;
88
88
89
    public Resource( int[] content, String charset, Integer version ) {
89
    public Resource( byte[] content, String charset, Integer version ) {
90
      this.charset = charset;
90
      this.charset = charset;
91
      this.content = content;
91
      this.content = content;
92
      this.version = version;
92
      this.version = version;
Lines 96-102 Link Here
96
      return charset;
96
      return charset;
97
    }
97
    }
98
98
99
    public int[] getContent() {
99
    public byte[] getContent() {
100
      return content;
100
      return content;
101
    }
101
    }
102
102
Lines 131-139 Link Here
131
   * @return the content of the resource or <code>null</code> if no resource
131
   * @return the content of the resource or <code>null</code> if no resource
132
   *         with the given <code>name</code> and <code>version</code> exists.
132
   *         with the given <code>name</code> and <code>version</code> exists.
133
   */
133
   */
134
  public int[] findResource( String name, Integer version ) {
134
  public byte[] findResource( String name, Integer version ) {
135
    ParamCheck.notNull( name, "name" );
135
    ParamCheck.notNull( name, "name" );
136
    int[] result = null;
136
    byte[] result = null;
137
    Resource resource = ( Resource )cache.get( createKey( name ) );
137
    Resource resource = ( Resource )cache.get( createKey( name ) );
138
    if( resource != null ) {
138
    if( resource != null ) {
139
      if(    ( version == null && resource.getVersion() == null )
139
      if(    ( version == null && resource.getVersion() == null )
Lines 197-203 Link Here
197
    ParamCheck.notNull( is, "is" );
197
    ParamCheck.notNull( is, "is" );
198
    String key = createKey( name );
198
    String key = createKey( name );
199
    try {
199
    try {
200
      int[] content = ResourceUtil.readBinary( is );
200
      byte[] content = ResourceUtil.readBinary( is );
201
      doRegister( name, null, RegisterOptions.NONE, key, content );
201
      doRegister( name, null, RegisterOptions.NONE, key, content );
202
    } catch ( IOException e ) {
202
    } catch ( IOException e ) {
203
      String text = "Failed to register resource ''{0}''.";
203
      String text = "Failed to register resource ''{0}''.";
Lines 215-221 Link Here
215
    boolean compress = shouldCompress( options );
215
    boolean compress = shouldCompress( options );
216
    String key = createKey( name );
216
    String key = createKey( name );
217
    try {
217
    try {
218
      int[] content = ResourceUtil.read( is, charset, compress );
218
      byte[] content = ResourceUtil.read( is, charset, compress );
219
      doRegister( name, charset, options, key, content );
219
      doRegister( name, charset, options, key, content );
220
    } catch ( IOException ioe ) {
220
    } catch ( IOException ioe ) {
221
      String msg = "Failed to register resource: " + name;
221
      String msg = "Failed to register resource: " + name;
Lines 361-367 Link Here
361
    if( !repository.containsKey( key ) ) {
361
    if( !repository.containsKey( key ) ) {
362
      boolean compress = shouldCompress( options );
362
      boolean compress = shouldCompress( options );
363
      try {
363
      try {
364
        int[] content = ResourceUtil.read( name, charset, compress, this );
364
        byte[] content = ResourceUtil.read( name, charset, compress, this );
365
        doRegister( name, charset, options, key, content );
365
        doRegister( name, charset, options, key, content );
366
      } catch ( IOException e ) {
366
      } catch ( IOException e ) {
367
        String text = "Failed to register resource ''{0}''.";
367
        String text = "Failed to register resource ''{0}''.";
Lines 376-382 Link Here
376
                           String charset,
376
                           String charset,
377
                           RegisterOptions options,
377
                           RegisterOptions options,
378
                           String key,
378
                           String key,
379
                           int[] content )
379
                           byte[] content )
380
    throws IOException
380
    throws IOException
381
  {
381
  {
382
    Integer version = computeVersion( content, options );
382
    Integer version = computeVersion( content, options );
Lines 407-413 Link Here
407
    }
407
    }
408
  }
408
  }
409
409
410
  private static Integer computeVersion( int[] content, RegisterOptions options ) {
410
  private static Integer computeVersion( byte[] content, RegisterOptions options ) {
411
    Integer result = null;
411
    Integer result = null;
412
    if( content != null && shouldVersion( options ) ) {
412
    if( content != null && shouldVersion( options ) ) {
413
      int version = 0;
413
      int version = 0;
(-)src/org/eclipse/rwt/internal/resources/ResourceUtil.java (-48 / +20 lines)
Lines 23-35 Link Here
23
public final class ResourceUtil {
23
public final class ResourceUtil {
24
24
25
  // TODO [rh] avoid passing around the same set of arguments again and again
25
  // TODO [rh] avoid passing around the same set of arguments again and again
26
  static int[] read( String name,
26
  static byte[] read( String name,
27
                     String charset,
27
                      String charset,
28
                     boolean compress,
28
                      boolean compress,
29
                     IResourceManager resourceManager )
29
                      IResourceManager resourceManager )
30
    throws IOException
30
    throws IOException
31
  {
31
  {
32
    int[] result;
32
    byte[] result;
33
    if( charset != null ) {
33
    if( charset != null ) {
34
      result = readText( name, charset, compress, resourceManager );
34
      result = readText( name, charset, compress, resourceManager );
35
    } else {
35
    } else {
Lines 38-45 Link Here
38
    return result;
38
    return result;
39
  }
39
  }
40
40
41
  static int[] read( InputStream is, String charset, boolean compress ) throws IOException {
41
  static byte[] read( InputStream is, String charset, boolean compress ) throws IOException {
42
    int[] result;
42
    byte[] result;
43
    if( charset != null ) {
43
    if( charset != null ) {
44
      result = readText( is, charset, compress );
44
      result = readText( is, charset, compress );
45
    } else {
45
    } else {
Lines 48-61 Link Here
48
    return result;
48
    return result;
49
  }
49
  }
50
50
51
  static void write( File toWrite, int[] content ) throws IOException {
51
  static void write( File toWrite, byte[] content ) throws IOException {
52
    FileOutputStream fos = new FileOutputStream( toWrite );
52
    FileOutputStream fos = new FileOutputStream( toWrite );
53
    try {
53
    try {
54
      OutputStream out = new BufferedOutputStream( fos );
54
      OutputStream out = new BufferedOutputStream( fos );
55
      try {
55
      try {
56
        for( int i = 0; i < content.length; i++ ) {
56
        out.write( content );
57
          out.write( content[ i ] );
58
        }
59
      } finally {
57
      } finally {
60
        out.close();
58
        out.close();
61
      }
59
      }
Lines 70-84 Link Here
70
    // TODO [rst] Add to concatenation buffer
68
    // TODO [rst] Add to concatenation buffer
71
  }
69
  }
72
70
73
  private static int[] readText( String name,
71
  private static byte[] readText( String name,
74
                                 String charset,
72
                                  String charset,
75
                                 boolean compress,
73
                                  boolean compress,
76
                                 IResourceManager resourceManager )
74
                                  IResourceManager resourceManager )
77
    throws IOException
75
    throws IOException
78
  {
76
  {
79
    // read resource
77
    // read resource
80
    InputStream is = openStream( name, resourceManager );
78
    InputStream is = openStream( name, resourceManager );
81
    int[] result;
79
    byte[] result;
82
    try {
80
    try {
83
      result = readText( is, charset, compress );
81
      result = readText( is, charset, compress );
84
    } finally {
82
    } finally {
Lines 87-93 Link Here
87
    return result;
85
    return result;
88
  }
86
  }
89
87
90
  static int[] readText( InputStream is, String charset, boolean compress ) throws IOException {
88
  static byte[] readText( InputStream is, String charset, boolean compress ) throws IOException {
91
    StringBuffer text = new StringBuffer();
89
    StringBuffer text = new StringBuffer();
92
    InputStreamReader reader = new InputStreamReader( is, charset );
90
    InputStreamReader reader = new InputStreamReader( is, charset );
93
    BufferedReader br = new BufferedReader( reader );
91
    BufferedReader br = new BufferedReader( reader );
Lines 101-137 Link Here
101
    } finally {
99
    } finally {
102
      br.close();
100
      br.close();
103
    }
101
    }
104
    // compress (JavaScript-) buffer if requested
105
    if( compress ) {
102
    if( compress ) {
106
      compress( text );
103
      compress( text );
107
    }
104
    }
108
    // write just read resource to byte array stream
105
    return text.toString().getBytes( HTTP.CHARSET_UTF_8 );
109
    byte[] bytes;
110
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
111
    try {
112
      OutputStreamWriter osw = new OutputStreamWriter( baos, HTTP.CHARSET_UTF_8 );
113
      try {
114
        osw.write( text.toString() );
115
        osw.flush();
116
      } finally {
117
        osw.close();
118
      }
119
      bytes = baos.toByteArray();
120
    } finally {
121
      baos.close();
122
    }
123
    // convert byte[] to int[] and return
124
    int[] result = new int[ bytes.length ];
125
    for( int i = 0; i < result.length; i++ ) {
126
      result[ i ] = ( bytes[ i ] & 0x0ff );
127
    }
128
    return result;
129
  }
106
  }
130
107
131
  private static int[] readBinary( String name, IResourceManager resourceManager ) 
108
  private static byte[] readBinary( String name, IResourceManager resourceManager ) 
132
    throws IOException 
109
    throws IOException 
133
  {
110
  {
134
    int[] result;
111
    byte[] result;
135
    InputStream is = openStream( name, resourceManager );
112
    InputStream is = openStream( name, resourceManager );
136
    try {
113
    try {
137
      result = readBinary( is );
114
      result = readBinary( is );
Lines 141-147 Link Here
141
    return result;
118
    return result;
142
  }
119
  }
143
120
144
  static int[] readBinary( InputStream stream ) throws IOException {
121
  static byte[] readBinary( InputStream stream ) throws IOException {
145
    ByteArrayOutputStream bufferedResult = new ByteArrayOutputStream();
122
    ByteArrayOutputStream bufferedResult = new ByteArrayOutputStream();
146
    BufferedInputStream bufferedStream = new BufferedInputStream( stream );
123
    BufferedInputStream bufferedStream = new BufferedInputStream( stream );
147
    try {
124
    try {
Lines 154-165 Link Here
154
    } finally {
131
    } finally {
155
      bufferedStream.close();
132
      bufferedStream.close();
156
    }
133
    }
157
    byte[] bytes = bufferedResult.toByteArray();
134
    return bufferedResult.toByteArray();
158
    int[] result = new int[ bytes.length ];
159
    for( int i = 0; i < bytes.length; i++ ) {
160
      result[ i ] = bytes[ i ];
161
    }
162
    return result;
163
  }
135
  }
164
136
165
  private static InputStream openStream( String name, IResourceManager resourceManager ) 
137
  private static InputStream openStream( String name, IResourceManager resourceManager ) 
(-)src/org/eclipse/rwt/internal/resources/JSLibraryConcatenator_Test.java (-7 / +7 lines)
Lines 22-28 Link Here
22
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
22
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
23
23
24
    concatenator.startJSConcatenation();
24
    concatenator.startJSConcatenation();
25
    concatenator.appendJSLibrary( new File( "library.js"), new int[] { character } );
25
    concatenator.appendJSLibrary( new File( "library.js"), new byte[] { ( byte )character } );
26
26
27
    assertEquals( concatenator.getUncompressed()[ 0 ], character );
27
    assertEquals( concatenator.getUncompressed()[ 0 ], character );
28
    assertEquals( concatenator.getUncompressed()[ 1 ], '\n' );
28
    assertEquals( concatenator.getUncompressed()[ 1 ], '\n' );
Lines 34-40 Link Here
34
  public void testIgnoreConcatenation() {
34
  public void testIgnoreConcatenation() {
35
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
35
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
36
36
37
    concatenator.appendJSLibrary( new File( "library.js"), new int[] { 'a' } );
37
    concatenator.appendJSLibrary( new File( "library.js"), new byte[] { 'a' } );
38
    
38
    
39
    assertEquals( 0, concatenator.getUncompressed().length );
39
    assertEquals( 0, concatenator.getUncompressed().length );
40
  }
40
  }
Lines 43-49 Link Here
43
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
43
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
44
    
44
    
45
    concatenator.startJSConcatenation();
45
    concatenator.startJSConcatenation();
46
    concatenator.appendJSLibrary( new File( "library.js"), new int[ 0 ] );
46
    concatenator.appendJSLibrary( new File( "library.js"), new byte[ 0 ] );
47
    
47
    
48
    assertEquals( 0, concatenator.getUncompressed().length );
48
    assertEquals( 0, concatenator.getUncompressed().length );
49
  }
49
  }
Lines 52-58 Link Here
52
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
52
    JSLibraryConcatenator concatenator = new JSLibraryConcatenator();
53
    
53
    
54
    concatenator.startJSConcatenation();
54
    concatenator.startJSConcatenation();
55
    concatenator.appendJSLibrary( new File( "content.html"), new int[] { 'a' } );
55
    concatenator.appendJSLibrary( new File( "content.html"), new byte[] { 'a' } );
56
    
56
    
57
    assertEquals( 0, concatenator.getUncompressed().length );    
57
    assertEquals( 0, concatenator.getUncompressed().length );    
58
  }
58
  }
Lines 62-68 Link Here
62
    
62
    
63
    concatenator.startJSConcatenation();
63
    concatenator.startJSConcatenation();
64
    concatenator.getHashCode();
64
    concatenator.getHashCode();
65
    concatenator.appendJSLibrary( new File( "content.js"), new int[] { 'a' } );
65
    concatenator.appendJSLibrary( new File( "content.js"), new byte[] { 'a' } );
66
    
66
    
67
    assertEquals( 0, concatenator.getUncompressed().length );        
67
    assertEquals( 0, concatenator.getUncompressed().length );        
68
  }
68
  }
Lines 72-78 Link Here
72
    
72
    
73
    concatenator.startJSConcatenation();
73
    concatenator.startJSConcatenation();
74
    concatenator.getCompressed();
74
    concatenator.getCompressed();
75
    concatenator.appendJSLibrary( new File( "content.js"), new int[] { 'a' } );
75
    concatenator.appendJSLibrary( new File( "content.js"), new byte[] { 'a' } );
76
    
76
    
77
    assertEquals( 0, concatenator.getUncompressed().length );        
77
    assertEquals( 0, concatenator.getUncompressed().length );        
78
  }
78
  }
Lines 82-88 Link Here
82
    
82
    
83
    concatenator.startJSConcatenation();
83
    concatenator.startJSConcatenation();
84
    concatenator.getUncompressed();
84
    concatenator.getUncompressed();
85
    concatenator.appendJSLibrary( new File( "content.js"), new int[] { 'a' } );
85
    concatenator.appendJSLibrary( new File( "content.js"), new byte[] { 'a' } );
86
    
86
    
87
    assertEquals( 0, concatenator.getUncompressed().length );        
87
    assertEquals( 0, concatenator.getUncompressed().length );        
88
  }
88
  }
(-)src/org/eclipse/rwt/internal/resources/ResourceManagerImpl_Test.java (-12 / +12 lines)
Lines 273-280 Link Here
273
    manager.register( resource, HTTP.CHARSET_UTF_8, RegisterOptions.COMPRESS );
273
    manager.register( resource, HTTP.CHARSET_UTF_8, RegisterOptions.COMPRESS );
274
274
275
    File resourceFile = getResourceCopyFile( resource );
275
    File resourceFile = getResourceCopyFile( resource );
276
    int[] origin = read( openStream( resource ) );
276
    byte[] origin = read( openStream( resource ) );
277
    int[] copy = read( resourceFile );
277
    byte[] copy = read( resourceFile );
278
    assertTrue( "Resource not registered", manager.isRegistered( resource ) );
278
    assertTrue( "Resource not registered", manager.isRegistered( resource ) );
279
    assertTrue( "Resource was not written to disk", resourceFile.exists() );
279
    assertTrue( "Resource was not written to disk", resourceFile.exists() );
280
    assertTrue( "Compressed resource too big", origin.length > copy.length );
280
    assertTrue( "Compressed resource too big", origin.length > copy.length );
Lines 394-402 Link Here
394
394
395
    manager.register( ISO_RESOURCE, charset );
395
    manager.register( ISO_RESOURCE, charset );
396
396
397
    int[] expected = read( openStream( UTF_8_RESOURCE ) );
397
    byte[] expected = read( openStream( UTF_8_RESOURCE ) );
398
    File copiedFile = getResourceCopyFile( ISO_RESOURCE );
398
    File copiedFile = getResourceCopyFile( ISO_RESOURCE );
399
    int[] actual = read( copiedFile );
399
    byte[] actual = read( copiedFile );
400
    assertEquals( charset, manager.getCharset( ISO_RESOURCE ) );
400
    assertEquals( charset, manager.getCharset( ISO_RESOURCE ) );
401
    assertEquals( expected.length, actual.length );
401
    assertEquals( expected.length, actual.length );
402
    assertTrue( Arrays.equals( actual, expected ) );
402
    assertTrue( Arrays.equals( actual, expected ) );
Lines 406-413 Link Here
406
    ResourceManagerImpl manager = getResourceManager( DELIVER_BY_SERVLET );
406
    ResourceManagerImpl manager = getResourceManager( DELIVER_BY_SERVLET );
407
    manager.register( ISO_RESOURCE, "ISO-8859-1" );
407
    manager.register( ISO_RESOURCE, "ISO-8859-1" );
408
    
408
    
409
    int[] expected = read( openStream( UTF_8_RESOURCE ) );
409
    byte[] expected = read( openStream( UTF_8_RESOURCE ) );
410
    int[] actual = manager.findResource( ISO_RESOURCE, null );
410
    byte[] actual = manager.findResource( ISO_RESOURCE, null );
411
    assertEquals( expected.length, actual.length );
411
    assertEquals( expected.length, actual.length );
412
    assertTrue( Arrays.equals( actual, expected ) );
412
    assertTrue( Arrays.equals( actual, expected ) );
413
  }
413
  }
Lines 492-515 Link Here
492
  ///////////////////
492
  ///////////////////
493
  // helping methods
493
  // helping methods
494
494
495
  private void assertEquals( int[] origin, int[] copy ) {
495
  private void assertEquals( byte[] origin, byte[] copy ) {
496
    assertEquals( "Content sizes are different", origin.length, copy.length );
496
    assertEquals( "Content sizes are different", origin.length, copy.length );
497
    for( int i = 0; i < copy.length; i++ ) {
497
    for( int i = 0; i < copy.length; i++ ) {
498
      assertEquals( "Content is different", origin[ i ], copy[ i ] );
498
      assertEquals( "Content is different", origin[ i ], copy[ i ] );
499
    }
499
    }
500
  }    
500
  }    
501
501
502
  private static int[] read( File file ) throws IOException {
502
  private static byte[] read( File file ) throws IOException {
503
    return read( new FileInputStream( file ) );
503
    return read( new FileInputStream( file ) );
504
  }
504
  }
505
505
506
  private static int[] read( InputStream input ) throws IOException {
506
  private static byte[] read( InputStream input ) throws IOException {
507
    BufferedInputStream bis = new BufferedInputStream( input );
507
    BufferedInputStream bis = new BufferedInputStream( input );
508
    int[] result = null;
508
    byte[] result = null;
509
    try {
509
    try {
510
      result = new int[ bis.available() ];
510
      result = new byte[ bis.available() ];
511
      for( int i = 0; i < result.length; i++ ) {
511
      for( int i = 0; i < result.length; i++ ) {
512
        result[ i ] = bis.read();
512
        result[ i ] = ( byte )bis.read();
513
      }
513
      }
514
    } finally {
514
    } finally {
515
      bis.close();
515
      bis.close();
(-)src/org/eclipse/rwt/internal/resources/ResourceUtil_Test.java (-22 / +19 lines)
Lines 75-82 Link Here
75
    JSLibraryConcatenator jsConcatenator = RWTFactory.getJSLibraryConcatenator();
75
    JSLibraryConcatenator jsConcatenator = RWTFactory.getJSLibraryConcatenator();
76
    jsConcatenator.startJSConcatenation();
76
    jsConcatenator.startJSConcatenation();
77
    File file = File.createTempFile( "test", ".js" );
77
    File file = File.createTempFile( "test", ".js" );
78
    ResourceUtil.write( file, getStringAsIntArray( "foo" ) );
78
    ResourceUtil.write( file, "foo".getBytes( "UTF-8" ) );
79
    ResourceUtil.write( file, getStringAsIntArray( "bar" ) );
79
    ResourceUtil.write( file, "bar".getBytes( "UTF-8" ) );
80
    String result = jsConcatenator.getContent();
80
    String result = jsConcatenator.getContent();
81
    assertEquals( "foo\nbar\n", result );
81
    assertEquals( "foo\nbar\n", result );
82
  }
82
  }
Lines 84-119 Link Here
84
  public void testReadText() throws IOException {
84
  public void testReadText() throws IOException {
85
    String input = createTestString( 10000 );
85
    String input = createTestString( 10000 );
86
    InputStream inputStream = new ByteArrayInputStream( input.getBytes( "UTF-8" ) );
86
    InputStream inputStream = new ByteArrayInputStream( input.getBytes( "UTF-8" ) );
87
    int[] result = ResourceUtil.readText( inputStream, "UTF-8", false );
87
    
88
    byte[] bytes = toByteArray( result );
88
    byte[] result = ResourceUtil.readText( inputStream, "UTF-8", false );
89
    assertEquals( input, new String( bytes ) );
89
    
90
    assertEquals( input, new String( result ) );
90
  }
91
  }
91
92
92
  private static byte[] toByteArray( int[] result ) {
93
  public void testWriteText() throws IOException {
93
    byte[] bytes = new byte[ result.length ];
94
    String input = createTestString( 10000 );
94
    for( int i = 0; i < bytes.length; i++ ) {
95
    byte[] content = input.getBytes( "UTF-8" );
95
      bytes[ i ] = ( byte )result[ i ];
96
    File tempFile = File.createTempFile( "rap-", ".test" );
96
    }
97
    tempFile.deleteOnExit();
97
    return bytes;
98
99
    ResourceUtil.write( tempFile, content );
100
101
    byte[] result = ResourceUtil.readText( new FileInputStream( tempFile ), "UTF-8", false );
102
    assertEquals( input, new String( result ) );
98
  }
103
  }
99
104
100
  private static String createTestString( int length ) {
105
  private static String createTestString( int length ) {
101
    StringBuffer buffer = new StringBuffer( length );
106
    StringBuffer buffer = new StringBuffer( length );
102
    for( int i = 0; i < length; i++ ) {
107
    buffer.append( 'Ü' );
103
      buffer.append( (char) ( 32 + ( i % 32 ) ) );
108
    for( int i = 1; i < length; i++ ) {
109
      buffer.append( ( char )( 32 + ( i % 32 ) ) );
104
    }
110
    }
105
    return buffer.toString();
111
    return buffer.toString();
106
  }
112
  }
107
113
108
  private static int[] getStringAsIntArray( String string ) {
109
    byte[] bytes = string.getBytes();
110
    int[] content = new int[ bytes.length ];
111
    for( int i = 0; i < content.length; i++ ) {
112
      content[ i ] = ( bytes[ i ] & 0x0ff );
113
    }
114
    return content;
115
  }
116
117
  protected void setUp() throws Exception {
114
  protected void setUp() throws Exception {
118
    Fixture.createApplicationContext();
115
    Fixture.createApplicationContext();
119
    Fixture.createServiceContext();
116
    Fixture.createServiceContext();

Return to bug 346104