Package com.onionnetworks.util

Examples of com.onionnetworks.util.Buffer


  private static final void encodeDecode(FECCode encode, FECCode decode, int index[]) {
    byte[] src = new byte[KK * PACKET_SIZE];
    Util.rand.nextBytes(src);
    Buffer[] srcBufs = new Buffer[KK];
    for (int i = 0; i < srcBufs.length; i++)
      srcBufs[i] = new Buffer(src, i * PACKET_SIZE, PACKET_SIZE);

    byte[] repair = new byte[KK * PACKET_SIZE];
    Buffer[] repairBufs = new Buffer[KK];
    for (int i = 0; i < repairBufs.length; i++) {
      repairBufs[i] = new Buffer(repair, i * PACKET_SIZE, PACKET_SIZE);
    }

    encode.encode(srcBufs, repairBufs, index);
    decode.decode(repairBufs, index);

View Full Code Here


    byte[] src = new byte[KK * PACKET_SIZE];
    Util.rand.nextBytes(src);
    Buffer[] srcBufs = new Buffer[KK];
    for (int i = 0; i < srcBufs.length; i++)
      srcBufs[i] = new Buffer(src, i * PACKET_SIZE, PACKET_SIZE);

    byte[] repair = new byte[KK * PACKET_SIZE];
    Buffer[] repairBufs = new Buffer[KK];
    for (int i = 0; i < repairBufs.length; i++) {
      repairBufs[i] = new Buffer(repair, i * PACKET_SIZE, PACKET_SIZE);
    }

    int[] indexBackup = new int[index.length];
    System.arraycopy(index,0,indexBackup,0,index.length);

View Full Code Here

        Buffer[] buffers = new Buffer[k];
        // The data blocks are already in the correct positions in dataBlocks.
        for(int i=0;i<dataBlocks.length;i++) {
            if(dataBlocks[i].length != blockLength) throw new IllegalArgumentException();
            if(!dataBlocksPresent[i]) continue;
            buffers[i] = new Buffer(dataBlocks[i], 0, blockLength);
            blockNumbers[i] = i;
        }
        int target = 0;
        // Fill in the gaps with the check blocks.
        for(int i=0;i<checkBlocks.length;i++) {
            if(!checkBlocksPresent[i]) continue;
            if(checkBlocks[i].length != blockLength) throw new IllegalArgumentException();
            while(target < dataBlocks.length && buffers[target] != null) target++; // Scan for slot.
            if(target >= dataBlocks.length) continue;
            // Decode into the slot for the relevant data block.
            buffers[target] = new Buffer(dataBlocks[target]);
            // Provide the data from the check block.
            blockNumbers[target] = i + dataBlocks.length;
            System.arraycopy(checkBlocks[i], 0, dataBlocks[target], 0, blockLength);
        }
       
View Full Code Here

        PureCode codec = getCodec(k, n);
        Buffer[] data = new Buffer[dataBlocks.length];
        for(int i=0;i<data.length;i++) {
            if(dataBlocks[i] == null || dataBlocks[i].length != blockLength)
                throw new IllegalArgumentException();
            data[i] = new Buffer(dataBlocks[i]);
        }
        int mustEncode = 0;
        for(int i=0;i<checkBlocks.length;i++) {
            if(checkBlocks[i] == null || checkBlocks[i].length != blockLength)
                throw new IllegalArgumentException();
            if(!checkBlocksPresent[i]) mustEncode++;
        }
        Buffer[] check = new Buffer[mustEncode];
        if(mustEncode == 0) return; // Done already.
        int[] toEncode = new int[mustEncode];
        int x = 0;
        for(int i=0;i<checkBlocks.length;i++) {
            if(checkBlocksPresent[i]) continue;
            check[x] = new Buffer(checkBlocks[i]);
            toEncode[x++] = i+dataBlocks.length;
        }
        codec.encode(data, check, toEncode);
    }
View Full Code Here

        }
        md.update(b,off,c);       
        byteCount += c;
        // this block is full
        if(byteCount == blockSize) {
            digestList.add(new Buffer(md.digest()));       
            byteCount = 0;
        }
        return c;
    }
View Full Code Here

        return c;
    }

    public void finish() {
        if (byteCount != 0) {
            digestList.add(new Buffer(md.digest()));
        }
        digests = (Buffer[]) digestList.toArray(new Buffer[0]);
        digestList = null;
    }
View Full Code Here

TOP

Related Classes of com.onionnetworks.util.Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.