Changeset 7311cf3
- Timestamp:
- Jan 19, 2017 1:25:56 PM (4 years ago)
- Branches:
- master
- Children:
- b66c780
- Parents:
- 60c93f1
- Location:
- core/java/src/net/i2p/util
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
core/java/src/net/i2p/util/ReusableGZIPInputStream.java
r60c93f1 r7311cf3 64 64 byte b[] = "hi, how are you today?".getBytes(); 65 65 try { 66 ByteArrayOutputStream baos = newByteArrayOutputStream(64);67 GZIPOutputStream o = newGZIPOutputStream(baos);66 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(64); 67 ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos); 68 68 o.write(b); 69 69 o.finish(); … … 72 72 73 73 ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire(); 74 in.initialize(new ByteArrayInputStream(compressed));74 in.initialize(new java.io.ByteArrayInputStream(compressed)); 75 75 byte rv[] = new byte[128]; 76 76 int read = in.read(rv); 77 if (! DataHelper.eq(rv, 0, b, 0, b.length))77 if (!net.i2p.data.DataHelper.eq(rv, 0, b, 0, b.length)) 78 78 throw new RuntimeException("foo, read=" + read); 79 79 else … … 85 85 private static boolean test(int size) { 86 86 byte b[] = new byte[size]; 87 new java.util.Random().nextBytes(b);87 RandomSource.getInstance().nextBytes(b); 88 88 try { 89 ByteArrayOutputStream baos = newByteArrayOutputStream(size);90 GZIPOutputStream o = newGZIPOutputStream(baos);89 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(size); 90 ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos); 91 91 o.write(b); 92 92 o.finish(); … … 95 95 96 96 ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire(); 97 in.initialize(new ByteArrayInputStream(compressed));98 ByteArrayOutputStream baos2 = newByteArrayOutputStream(size);97 in.initialize(new java.io.ByteArrayInputStream(compressed)); 98 java.io.ByteArrayOutputStream baos2 = new java.io.ByteArrayOutputStream(size); 99 99 byte rbuf[] = new byte[128]; 100 100 try { … … 105 105 baos2.write(rbuf, 0, read); 106 106 } 107 } catch ( IOException ioe) {107 } catch (java.io.IOException ioe) { 108 108 ioe.printStackTrace(); 109 long crcVal = in.getCurrentCRCVal();109 //long crcVal = in.getCurrentCRCVal(); 110 110 //try { in.verifyFooter(); } catch (IOException ioee) { 111 111 // ioee.printStackTrace(); … … 121 121 throw new RuntimeException("read length: " + rv.length + " expected: " + b.length); 122 122 123 if (! DataHelper.eq(rv, 0, b, 0, b.length)) {123 if (!net.i2p.data.DataHelper.eq(rv, 0, b, 0, b.length)) { 124 124 throw new RuntimeException("foo, read=" + rv.length); 125 125 } else { 126 System.out.println("match, w00t ");126 System.out.println("match, w00t @ " + size); 127 127 return true; 128 128 } -
core/java/src/net/i2p/util/ReusableGZIPOutputStream.java
r60c93f1 r7311cf3 90 90 for (int i = 0; i < 2; i++) 91 91 test(); 92 for (int i = 500; i < 64*1024; i++) {92 for (int i = 0; i < 64*1024; i++) { 93 93 if (!test(i)) break; 94 94 } … … 107 107 ReusableGZIPOutputStream.release(o); 108 108 109 GZIPInputStream in = new GZIPInputStream(newByteArrayInputStream(compressed));109 ResettableGZIPInputStream in = new ResettableGZIPInputStream(new java.io.ByteArrayInputStream(compressed)); 110 110 byte rv[] = new byte[128]; 111 111 int read = in.read(rv); … … 119 119 private static boolean test(int size) { 120 120 byte b[] = new byte[size]; 121 new java.util.Random().nextBytes(b);121 RandomSource.getInstance().nextBytes(b); 122 122 try { 123 123 ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire(); … … 128 128 ReusableGZIPOutputStream.release(o); 129 129 130 GZIPInputStream in = new GZIPInputStream(newByteArrayInputStream(compressed));131 ByteArrayOutputStream baos2 = new ByteArrayOutputStream( 256*1024);130 ResettableGZIPInputStream in = new ResettableGZIPInputStream(new java.io.ByteArrayInputStream(compressed)); 131 ByteArrayOutputStream baos2 = new ByteArrayOutputStream(size); 132 132 byte rbuf[] = new byte[128]; 133 133 while (true) {
Note: See TracChangeset
for help on using the changeset viewer.