Changeset 7311cf3


Ignore:
Timestamp:
Jan 19, 2017 1:25:56 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
b66c780
Parents:
60c93f1
Message:

Utils: Gzip test code refresh

Location:
core/java/src/net/i2p/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/ReusableGZIPInputStream.java

    r60c93f1 r7311cf3  
    6464        byte b[] = "hi, how are you today?".getBytes();
    6565        try {
    66             ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
    67             GZIPOutputStream o = new GZIPOutputStream(baos);
     66            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(64);
     67            ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos);
    6868            o.write(b);
    6969            o.finish();
     
    7272           
    7373            ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire();
    74             in.initialize(new ByteArrayInputStream(compressed));
     74            in.initialize(new java.io.ByteArrayInputStream(compressed));
    7575            byte rv[] = new byte[128];
    7676            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))
    7878                throw new RuntimeException("foo, read=" + read);
    7979            else
     
    8585    private static boolean test(int size) {
    8686        byte b[] = new byte[size];
    87         new java.util.Random().nextBytes(b);
     87        RandomSource.getInstance().nextBytes(b);
    8888        try {
    89             ByteArrayOutputStream baos = new ByteArrayOutputStream(size);
    90             GZIPOutputStream o = new GZIPOutputStream(baos);
     89            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(size);
     90            ResettableGZIPOutputStream o = new ResettableGZIPOutputStream(baos);
    9191            o.write(b);
    9292            o.finish();
     
    9595           
    9696            ReusableGZIPInputStream in = ReusableGZIPInputStream.acquire();
    97             in.initialize(new ByteArrayInputStream(compressed));
    98             ByteArrayOutputStream baos2 = new ByteArrayOutputStream(size);
     97            in.initialize(new java.io.ByteArrayInputStream(compressed));
     98            java.io.ByteArrayOutputStream baos2 = new java.io.ByteArrayOutputStream(size);
    9999            byte rbuf[] = new byte[128];
    100100            try {
     
    105105                    baos2.write(rbuf, 0, read);
    106106                }
    107             } catch (IOException ioe) {
     107            } catch (java.io.IOException ioe) {
    108108                ioe.printStackTrace();
    109                 long crcVal = in.getCurrentCRCVal();
     109                //long crcVal = in.getCurrentCRCVal();
    110110                //try { in.verifyFooter(); } catch (IOException ioee) {
    111111                //    ioee.printStackTrace();
     
    121121                throw new RuntimeException("read length: " + rv.length + " expected: " + b.length);
    122122           
    123             if (!DataHelper.eq(rv, 0, b, 0, b.length)) {
     123            if (!net.i2p.data.DataHelper.eq(rv, 0, b, 0, b.length)) {
    124124                throw new RuntimeException("foo, read=" + rv.length);
    125125            } else {
    126                 System.out.println("match, w00t");
     126                System.out.println("match, w00t @ " + size);
    127127                return true;
    128128            }
  • core/java/src/net/i2p/util/ReusableGZIPOutputStream.java

    r60c93f1 r7311cf3  
    9090            for (int i = 0; i < 2; i++)
    9191                test();
    92             for (int i = 500; i < 64*1024; i++) {
     92            for (int i = 0; i < 64*1024; i++) {
    9393                if (!test(i)) break;
    9494            }
     
    107107            ReusableGZIPOutputStream.release(o);
    108108           
    109             GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
     109            ResettableGZIPInputStream in = new ResettableGZIPInputStream(new java.io.ByteArrayInputStream(compressed));
    110110            byte rv[] = new byte[128];
    111111            int read = in.read(rv);
     
    119119    private static boolean test(int size) {
    120120        byte b[] = new byte[size];
    121         new java.util.Random().nextBytes(b);
     121        RandomSource.getInstance().nextBytes(b);
    122122        try {
    123123            ReusableGZIPOutputStream o = ReusableGZIPOutputStream.acquire();
     
    128128            ReusableGZIPOutputStream.release(o);
    129129           
    130             GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(compressed));
    131             ByteArrayOutputStream baos2 = new ByteArrayOutputStream(256*1024);
     130            ResettableGZIPInputStream in = new ResettableGZIPInputStream(new java.io.ByteArrayInputStream(compressed));
     131            ByteArrayOutputStream baos2 = new ByteArrayOutputStream(size);
    132132            byte rbuf[] = new byte[128];
    133133            while (true) {
Note: See TracChangeset for help on using the changeset viewer.