Examples of StorageFormatException


Examples of freenet.support.io.StorageFormatException

    SplitFileInserterCrossSegmentStorage(SplitFileInserterStorage parent, DataInputStream dis,
            int segNo) throws StorageFormatException, IOException {
        this.segNo = segNo;
        this.parent = parent;
        this.dataBlockCount = dis.readInt();
        if(dataBlockCount <= 0) throw new StorageFormatException("Negative cross-segment data block count");
        this.crossCheckBlockCount = dis.readInt();
        if(crossCheckBlockCount <= 0) throw new StorageFormatException("Negative cross-check block count");
        this.totalBlocks = dataBlockCount + crossCheckBlockCount;
        if(totalBlocks > FECCodec.MAX_TOTAL_BLOCKS_PER_SEGMENT)
            throw new StorageFormatException("Bogus total block count");
        segments = new SplitFileInserterSegmentStorage[totalBlocks];
        blockNumbers = new int[totalBlocks];
        for(int i=0;i<totalBlocks;i++) {
            int readSegmentNumber = dis.readInt();
            if(readSegmentNumber < 0 || readSegmentNumber >= parent.segments.length)
                throw new StorageFormatException("Bogus segment number "+readSegmentNumber);
            int readBlockNumber = dis.readInt();
            SplitFileInserterSegmentStorage segment = parent.segments[readSegmentNumber];
            if(readBlockNumber < 0 ||
                    (readBlockNumber >= segment.dataBlockCount + segment.crossCheckBlockCount)
                    || (i < dataBlockCount && readBlockNumber >= segment.dataBlockCount)
                    || (i >= dataBlockCount && readBlockNumber < segment.dataBlockCount))
                throw new StorageFormatException("Bogus block number "+readBlockNumber+" for slot "+i);
            segments[i] = segment;
            blockNumbers[i] = readBlockNumber;
        }
        for(int i=0;i<crossCheckBlockCount;i++) {
            segments[i+dataBlockCount].setCrossCheckBlock(this, blockNumbers[i+dataBlockCount], i+dataBlockCount);
        }
        statusLength = dis.readInt();
        if(statusLength < 0) throw new StorageFormatException("Bogus status length");
        try {
            CountedOutputStream cos = new CountedOutputStream(new NullOutputStream());
            DataOutputStream dos = new DataOutputStream(cos);
            innerStoreStatus(dos);
            dos.close();
            int computedStatusLength = (int) cos.written() + parent.checker.checksumLength();
            if(computedStatusLength > statusLength)
                throw new StorageFormatException("Stored status length smaller than required");
        } catch (IOException e) {
            throw new Error(e); // Impossible
        }
    }
View Full Code Here

Examples of freenet.support.io.StorageFormatException

   
    void readStatus() throws IOException, ChecksumFailedException, StorageFormatException {
        byte[] data = new byte[statusLength-parent.checker.checksumLength()];
        parent.preadChecksummed(parent.crossSegmentStatusOffset(segNo), data, 0, data.length);
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data));
        if(dis.readInt() != segNo) throw new StorageFormatException("Bad segment number");
        encoded = dis.readBoolean();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.