Package freenet.support.api

Examples of freenet.support.api.LockableRandomAccessBuffer


            readBytes = is.read(buf);
            assertTrue(readBytes > 0);
            assertTrue(Arrays.equals(Arrays.copyOfRange(buf, 0, readBytes), Arrays.copyOfRange(data, moved, moved+readBytes)));
            moved += readBytes;
        }
        LockableRandomAccessBuffer raf = bucket.toRandomAccessBuffer();
        assertEquals(length, raf.size());
        RAFBucket wrapped = new RAFBucket(raf);
        assertTrue(BucketTools.equalBuckets(bucket, wrapped));
        for(int i=0;i<100;i++) {
            int end = length == 1 ? 1 : r.nextInt(length)+1;
            int start = r.nextInt(end);
View Full Code Here


    // Otherwise the file is too big to fit into one block
    // We therefore must make a splitfile
    // Job of SplitHandler: when the splitinserter has the metadata,
    // insert it. Then when the splitinserter has finished, and the
    // metadata insert has finished too, tell the master callback.
    LockableRandomAccessBuffer dataRAF;
        try {
            dataRAF = data.toRandomAccessBuffer();
        } catch (IOException e) {
            throw new InsertException(InsertExceptionMode.BUCKET_ERROR, e, null);
        }
View Full Code Here

    }

    @Override
    public LockableRandomAccessBuffer toRandomAccessBuffer() {
        readOnly = true;
        LockableRandomAccessBuffer raf = new ByteArrayRandomAccessBuffer(data, 0, data.length, true);
        return raf;
    }
View Full Code Here

    public static LockableRandomAccessBuffer create(DataInputStream dis, FilenameGenerator fg, PersistentFileTracker persistentFileTracker, MasterSecret masterKey)
    throws IOException, StorageFormatException, ResumeFailedException {
        EncryptedRandomAccessBufferType type = EncryptedRandomAccessBufferType.getByBitmask(dis.readInt());
        if(type == null)
            throw new StorageFormatException("Unknown EncryptedRandomAccessBufferType");
        LockableRandomAccessBuffer underlying = BucketTools.restoreRAFFrom(dis, fg, persistentFileTracker, masterKey);
        try {
            return new EncryptedRandomAccessBuffer(type, underlying, masterKey, false);
        } catch (GeneralSecurityException e) {
            Logger.error(EncryptedRandomAccessBuffer.class, "Crypto error resuming: "+e, e);
            throw new ResumeFailedException(e);
View Full Code Here

    protected final void migrate() throws IOException {
        try {
            lock.writeLock().lock();
            if(closed) return;
            if(underlying == null) throw new IOException("Already freed");
            LockableRandomAccessBuffer successor = innerMigrate(underlying);
            if(successor == null) throw new NullPointerException();
            RAFLock newLock = null;
            if(lockOpenCount > 0) {
                try {
                    newLock = successor.lockOpen();
                } catch (IOException e) {
                    successor.close();
                    successor.free();
                    throw e;
                }
            }
            if(lockOpenCount > 0)
                underlyingLock.unlock();
View Full Code Here

                realSize += TempBucketFactory.CRYPT_TYPE.headerLen;
                paddedSize = PaddedEphemerallyEncryptedBucket.paddedLength(realSize, PaddedEphemerallyEncryptedBucket.MIN_PADDED_SIZE);
                if(logMINOR) Logger.minor(this, "Encrypting and padding "+size+" to "+paddedSize);
            }
        }
        LockableRandomAccessBuffer raf = factory.makeRAF(paddedSize);
        if(secret != null) {
            if(realSize != paddedSize)
                raf = new PaddedRandomAccessBuffer(raf, realSize);
            try {
                raf = new EncryptedRandomAccessBuffer(TempBucketFactory.CRYPT_TYPE, raf, secret, true);
View Full Code Here

        synchronized(this) {
            reallyEncrypt = this.reallyEncrypt;
        }
        if(reallyEncrypt) {
            // FIXME do the encryption in memory? Test it ...
            LockableRandomAccessBuffer ret = makeRAF(size);
            ret.pwrite(0, initialContents, offset, size);
            if(readOnly) ret = new ReadOnlyRandomAccessBuffer(ret);
            return ret;
        } else {
            return factory.makeRAF(initialContents, offset, size, readOnly);
        }
View Full Code Here

          long paddedSize = size;
          if(encrypt) {
              realSize += TempBucketFactory.CRYPT_TYPE.headerLen;
              paddedSize = PaddedEphemerallyEncryptedBucket.paddedLength(realSize, PaddedEphemerallyEncryptedBucket.MIN_PADDED_SIZE);
          }
          LockableRandomAccessBuffer ret = diskRAFFactory.makeRAF(paddedSize);
          if(encrypt) {
              if(realSize != paddedSize)
                  ret = new PaddedRandomAccessBuffer(ret, realSize);
              try {
                  ret = new EncryptedRandomAccessBuffer(CRYPT_TYPE, ret, secret, true);
View Full Code Here

            }
            return raf;
        } else {
            if(reallyEncrypt) {
                // FIXME do the encryption in memory? Test it ...
                LockableRandomAccessBuffer ret = makeRAF(size);
                ret.pwrite(0, initialContents, offset, size);
                if(readOnly) ret = new ReadOnlyRandomAccessBuffer(ret);
                return ret;
            }
            return diskRAFFactory.makeRAF(initialContents, offset, size, readOnly);
        }
View Full Code Here

        InputStream is = checker.checksumReaderWithLength(ois, new ArrayBucketFactory(), 1024*1024);
        dis = new DataInputStream(is);
        int version = dis.readInt();
        if(version != VERSION)
            throw new StorageFormatException("Bad version");
        LockableRandomAccessBuffer rafOrig = BucketTools.restoreRAFFrom(dis, persistentFG, persistentFileTracker, masterKey);
        if(originalData == null) {
            this.originalData = rafOrig;
        } else {
            // Check that it's the same, but use the passed-in one.
            if(!originalData.equals(rafOrig))
View Full Code Here

TOP

Related Classes of freenet.support.api.LockableRandomAccessBuffer

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.