Package org.exist.storage.io

Examples of org.exist.storage.io.VariableByteOutputStream


        final int ownerId = new Random().nextInt();
        final int mode = 0700;
        final int ownerGroupId = new Random().nextInt();

        final VariableByteOutputStream mockOstream = EasyMock.createMock(VariableByteOutputStream.class);
        final VariableByteInput mockIstream = EasyMock.createMock(VariableByteInput.class);

        final TestableUnixStylePermission permission = new TestableUnixStylePermission(mockSecurityManager, ownerId, ownerGroupId, mode);
       
        final long permissionVector = permission.getVector_testable();
       
        //expectations
        mockOstream.writeLong(permissionVector);
        expect(mockIstream.readLong()).andReturn(permissionVector);

        replay(mockSecurityManager, mockOstream, mockIstream);

        permission.write(mockOstream);
View Full Code Here


  }
 
  private int computeHashCode() {
    if (item instanceof NodeProxy) {
      NodeProxy proxy = (NodeProxy) item;
      VariableByteOutputStream buf = new VariableByteOutputStream();
      try {
        proxy.getNodeId().write(buf);
      } catch (IOException e) {
        throw new RuntimeException("unable to serialize node's id to compute hashCode", e);
      }
      return proxy.getDocument().getURI().hashCode() ^ Arrays.hashCode(buf.toByteArray());
    } else {
      return item.hashCode();
    }
  }
View Full Code Here

       
        final int groupId2 = 2;
        final int mode2 = Permission.READ;
        permission.addGroupACE(ACE_ACCESS_TYPE.DENIED, groupId2, mode2);
       
        final VariableByteOutputStream os = new VariableByteOutputStream();
       
        //write the acl out
        permission.write(os);
       
        verify(mockSecurityManager, mockDatabase, mockCurrentSubject);
       
        assertEquals(2, permission.getACECount());
       
        assertEquals(ACE_ACCESS_TYPE.ALLOWED, permission.getACEAccessType(0));
        assertEquals(userId1, permission.getACEId(0));
        assertEquals(ACE_TARGET.USER, permission.getACETarget(0));
        assertEquals(mode1, permission.getACEMode(0));
       
        assertEquals(ACE_ACCESS_TYPE.DENIED, permission.getACEAccessType(1));
        assertEquals(groupId2, permission.getACEId(1));
        assertEquals(ACE_TARGET.GROUP, permission.getACETarget(1));
        assertEquals(mode2, permission.getACEMode(1));
       
        //get the written acl data
        ByteArray buf = os.data();
        byte data[] = new byte[buf.size()];
        buf.copyTo(data, 0);
       
       
        //create a new permission instance
View Full Code Here

    public void write_and_read_are_balanced() throws EXistException, IOException {

        SymbolTable symbolTable = new SymbolTable(null, tmpDir);
        symbolTable.getSymbol("some-name");

        VariableByteOutputStream mockOs = EasyMock.createMock(VariableByteOutputStream.class);
        VariableByteInput mockIs = EasyMock.createMock(VariableByteInput.class);

        final Capture<Byte> byteCapture = new Capture<Byte>();
        final Capture<Integer> intCapture = new Capture<Integer>();
        final Capture<String> strCapture = new Capture<String>();

        //write expectations
        mockOs.writeByte(captureByte(byteCapture));
        mockOs.writeInt(captureInt(intCapture));
        mockOs.writeUTF(capture(strCapture));

        replay(mockOs);

        symbolTable.localNameSymbols.write(mockOs);
View Full Code Here

     *
     * @throws EXistException
     */
    private void saveSymbols() throws EXistException {
        try {
            final VariableByteOutputStream os = new VariableByteOutputStream(256);
            writeAll(os);
            final FileOutputStream fos = new FileOutputStream(getFile().getAbsolutePath(), false);
            fos.write(os.toByteArray());
            fos.close();
        } catch(final FileNotFoundException e) {
            throw new EXistException("File not found: " + this.getFile().getAbsolutePath());
        } catch(final IOException e) {
            throw new EXistException("IO error occurred while creating "
View Full Code Here

            if(collection.getId() == Collection.UNKNOWN_COLLECTION_ID) {
                collection.setId(getNextCollectionId(transaction));
            }
            final Value name = new CollectionStore.CollectionKey(collection.getURI().toString());
            final VariableByteOutputStream os = new VariableByteOutputStream(8);
            collection.write(this, os);
            final long address = collectionsDb.put(transaction, name, os.data(), true);
            if(address == BFile.UNKNOWN_ADDRESS) {
                //TODO : exception !!! -pb
                LOG.warn("could not store collection data for '" + collection.getURI() + "'");
                return;
            }
            collection.setAddress(address);
            os.close();

        } catch(final ReadOnlyException e) {
            LOG.warn(DATABASE_IS_READ_ONLY);
        } catch(final LockException e) {
            LOG.warn("Failed to acquire lock on " + collectionsDb.getFile().getName(), e);
View Full Code Here


        final Lock lock = collectionsDb.getLock();
        try {
            lock.acquire(Lock.WRITE_LOCK);
            final VariableByteOutputStream os = new VariableByteOutputStream(8);
            doc.write(os);
            final Value key = new CollectionStore.DocumentKey(doc.getCollection().getId(), doc.getResourceType(), doc.getDocId());
            collectionsDb.put(transaction, key, os.data(), true);
            //} catch (ReadOnlyException e) {
            //LOG.warn(DATABASE_IS_READ_ONLY);
        } catch(final LockException e) {
            LOG.warn("Failed to acquire lock on " + collectionsDb.getFile().getName());
        } catch(final IOException e) {
View Full Code Here

TOP

Related Classes of org.exist.storage.io.VariableByteOutputStream

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.