Package org.exist.dom

Examples of org.exist.dom.BinaryDocument


                    final DocumentMetadata meta = doc.getMetadata();
                   
                    final Date created = new Date(meta.getCreated());
                    final Date lastModified = new Date(meta.getLastModified());
   
                    BinaryDocument binary = destination.validateBinaryResource(txn, broker, newName, is, mimeType.getName(), -1, created, lastModified);
                   
                    binary = destination.addBinaryResource(txn, broker, binary, is, mimeType.getName(), -1, created, lastModified);
                   
                    source.removeXMLResource(txn, broker, doc.getFileURI());
                   
View Full Code Here


 
        } else {
          // store as binary resource
          is = new ByteArrayInputStream("".getBytes(UTF_8));
         
          final BinaryDocument blob = new BinaryDocument(db, collection, fileName);
 
          blob.getPermissions().setMode(DEFAULT_RESOURCE_PERM);

          collection.addBinaryResource(transaction, broker, blob, is,
              mimeType.getName(), 0L , new Date(), new Date());
 
        }
View Full Code Here

                        targetCollection.store(txn, broker, info, is, false);
                    } else {
                        final long size = file.length();
                        final FileInputStream is = new FileInputStream(file);
                        final BinaryDocument doc =
                                targetCollection.addBinaryResource(txn, broker, name, is, mime.getName(), size);
                        is.close();

                        final Permission permission = doc.getPermissions();
                        setPermissions(false, mime, permission);
                        doc.getMetadata().setMimeType(mime.getName());
                        broker.storeXMLResource(txn, doc);
                    }
                    mgr.commit(txn);
                } catch (final Exception e) {
                    mgr.abort(txn);
View Full Code Here

                final byte              type    = key.data()[key.start() + Collection.LENGTH_COLLECTION_ID + DocumentImpl.LENGTH_DOCUMENT_TYPE];
                final VariableByteInput istream = store.getAsStream( pointer );
                DocumentImpl      doc     = null;

                if( type == DocumentImpl.BINARY_FILE ) {
                    doc = new BinaryDocument( broker.getBrokerPool() );
                } else {
                    doc = new DocumentImpl( broker.getBrokerPool() );
                }
                doc.read( istream );
                docCount++;
View Full Code Here

   }
  
   public boolean getBin(DBBroker broker,String suffix)
      throws Exception
   {
      BinaryDocument binDoc = null;
      try {
         Collection top = broker.getCollection(XmldbURI.create("xmldb:exist:///"));
         System.out.println("count="+top.getDocumentCount(broker));
         MutableDocumentSet docs = new DefaultDocumentSet();
         top.getDocuments(broker,docs);
         XmldbURI [] uris = docs.getNames();
         for (int i=0; i<uris.length; i++) {
            System.out.println(i+": "+uris[i].toString());
         }
         //binDoc = (BinaryDocument)broker.getXMLResource(XmldbURI.create("xmldb:exist:///bin"),Lock.READ_LOCK);
         binDoc = (BinaryDocument)top.getDocument(broker,XmldbURI.create("xmldb:exist:///bin"));
         top.release(Lock.READ_LOCK);
         assertTrue(binDoc!=null);
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         broker.readBinaryResource(binDoc,os);
         String comp = os.size()>0 ? new String(os.toByteArray()) : "";
         System.out.println("Got: "+comp);
         return comp.equals(bin+suffix);
      } finally {
         if (binDoc!=null) {
            binDoc.getUpdateLock().release(Lock.READ_LOCK);
         }
      }
   }
View Full Code Here

        } else {
          // store as binary resource
          is = new FileInputStream(currentFile);

          BinaryDocument doc = currentDirectory.addBinaryResource(
              transaction, broker, fileName, is,
              mimeType.getName(), currentFile.length(), new Date(), new Date());

        }
      } catch (FileNotFoundException e) {
View Full Code Here

        final String xquery = "current-dateTime()";

        Main database = startupDatabase();
        try {
            //store the xquery document
            BinaryDocument binaryDoc = storeBinary(xqueryFilename, xquery, xqueryMimeType);
            assertNotNull(binaryDoc);
            assertEquals(xqueryMimeType, binaryDoc.getMetadata().getMimeType());

            //make a note of the binary documents uri
            final XmldbURI binaryDocUri = binaryDoc.getFileURI();

            //restart the database
            stopDatabase(database);
            Thread.sleep(3000);
            database = startupDatabase();

            //retrieve the xquery document
            binaryDoc = getBinary(binaryDocUri);
            assertNotNull(binaryDoc);

            //check the mimetype has been preserved across database restarts
            assertEquals(xqueryMimeType, binaryDoc.getMetadata().getMimeType());

        } finally {
            stopDatabase(database);
        }
    }
View Full Code Here

            e.printStackTrace();
        }
    }

    private BinaryDocument getBinary(XmldbURI uri) throws EXistException {
        BinaryDocument binaryDoc = null;
        Database pool = BrokerPool.getInstance();;

        DBBroker broker = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
View Full Code Here

        return binaryDoc;
    }

    private BinaryDocument storeBinary(String name,  String data, String mimeType) throws EXistException {
      BinaryDocument binaryDoc = null;
        Database pool = BrokerPool.getInstance();;

        DBBroker broker = null;
        TransactionManager transact = null;
        Txn transaction = null;
View Full Code Here

            assertNotNull(files);
           
            File f;
            IndexInfo info;
           
            BinaryDocument doc = test2.addBinaryResource(transaction, broker, TestConstants.TEST_BINARY_URI, "Some text data".getBytes(), null);
            assertNotNull(doc);
           
            // store some documents. Will be replaced below
            for (int i = 0; i < files.length; i++) {
                f = files[i];
View Full Code Here

TOP

Related Classes of org.exist.dom.BinaryDocument

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.