Examples of BinaryDocument


Examples of com.couchbase.client.java.document.BinaryDocument

        converter = new BinaryTranscoder();
    }

    @Test
    public void shouldEncodeBinary() {
        BinaryDocument document = BinaryDocument.create("id", Unpooled.copiedBuffer("value", CharsetUtil.UTF_8));
        Tuple2<ByteBuf, Integer> encoded = converter.encode(document);

        assertEquals("value", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.BINARY_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here

Examples of com.couchbase.client.java.document.BinaryDocument

        assertEquals(TranscoderUtils.BINARY_COMPAT_FLAGS, (long) encoded.value2());
    }

    @Test
    public void shouldDecodeCommonBinary() {
        BinaryDocument document = converter.decode("id",
                Unpooled.copiedBuffer("value", CharsetUtil.UTF_8), 0, 0,
                TranscoderUtils.BINARY_COMMON_FLAGS, ResponseStatus.SUCCESS);
        assertEquals("value", document.content().toString(CharsetUtil.UTF_8));
    }
View Full Code Here

Examples of com.couchbase.client.java.document.BinaryDocument

        assertEquals("value", document.content().toString(CharsetUtil.UTF_8));
    }

    @Test
    public void shouldDecodeLegacyBinary() {
        BinaryDocument document = converter.decode("id",
                Unpooled.copiedBuffer("value", CharsetUtil.UTF_8), 0, 0,
                TranscoderUtils.BINARY_COMPAT_FLAGS, ResponseStatus.SUCCESS);
        assertEquals("value", document.content().toString(CharsetUtil.UTF_8));
    }
View Full Code Here

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

Examples of org.exist.dom.BinaryDocument

 
        } 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

Examples of org.exist.dom.BinaryDocument

                        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

Examples of org.exist.dom.BinaryDocument

                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

Examples of org.exist.dom.BinaryDocument

   }
  
   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

Examples of org.exist.dom.BinaryDocument

        } 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

Examples of org.exist.dom.BinaryDocument

        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
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.