Search in sources :

Example 36 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class ModificationTimeTest method storeBinary.

private BinaryDocument storeBinary(final DBBroker broker, final Txn transaction, final String name, final String data, final String mimeType) throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final Collection root = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI);
    broker.saveCollection(transaction, root);
    assertNotNull(root);
    root.storeDocument(transaction, broker, XmldbURI.create(name), new StringInputSource(data.getBytes(UTF_8)), new MimeType(mimeType, MimeType.BINARY));
    return (BinaryDocument) root.getDocument(broker, XmldbURI.create(name));
}
Also used : BinaryDocument(org.exist.dom.persistent.BinaryDocument) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) MimeType(org.exist.util.MimeType)

Example 37 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class JournalXmlTest method largeJournalEntry_corrupt.

@Test
public void largeJournalEntry_corrupt() throws IllegalAccessException, EXistException, NoSuchFieldException, LockException, SAXException, PermissionDeniedException, IOException, InterruptedException {
    checkpointJournalAndSwitchFile();
    // generate a string filled with random a-z characters which is larger than the journal buffer
    // 3 * the journal buffer size
    final byte[] buf = new byte[Journal.BUFFER_SIZE * 3];
    final Random random = new Random();
    for (int i = 0; i < buf.length; i++) {
        final byte singleByteChar = (byte) ('a' + random.nextInt('z' - 'a' - 1));
        buf[i] = singleByteChar;
    }
    final String largeText = new String(buf, UTF_8);
    final String xml = "<large-text>" + largeText + "</large-text>";
    final InputSource source = new StringInputSource(xml);
    source.setEncoding("UTF-8");
    BrokerPool.FORCE_CORRUPTION = true;
    final TxnDoc<String> stored = store(COMMIT, source, "large-non-corrupt.xml");
    flushJournal();
    // shutdown the broker pool (without destroying the data dir)
    existEmbeddedServer.getBrokerPool().shutdown();
    // reset the corruption flag back to normal
    BrokerPool.FORCE_CORRUPTION = false;
    // check journal entries written for store
    assertPartialOrdered(store_expected(stored, 0, largeText), readLatestJournalEntries());
}
Also used : StringInputSource(org.exist.util.StringInputSource) InputSource(org.xml.sax.InputSource) StringInputSource(org.exist.util.StringInputSource) Random(java.util.Random) Test(org.junit.Test)

Example 38 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class GetXMLResourceNoLockTest method storeTestResource.

private void storeTestResource() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = BrokerPool.getInstance();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = transact.beginTransaction()) {
        final Collection collection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        broker.saveCollection(transaction, collection);
        broker.storeDocument(transaction, DOCUMENT_NAME_URI, new StringInputSource(EMPTY_BINARY_FILE.getBytes(UTF_8)), MimeType.TEXT_TYPE, collection);
        transact.commit(transaction);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 39 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class InspectModuleTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection testCollection = broker.getOrCreateCollection(transaction, TEST_COLLECTION);
        broker.storeDocument(transaction, TEST_MODULE, new StringInputSource(MODULE.getBytes(UTF_8)), MimeType.XQUERY_TYPE, testCollection);
        broker.saveCollection(transaction, testCollection);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 40 with StringInputSource

use of org.exist.util.StringInputSource in project exist by eXist-db.

the class XQueryDeclareContextItemTest method setup.

@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        broker.storeDocument(transaction, XmldbURI.create("sysevent.xml"), new StringInputSource(SYSEVENT_XML), MimeType.XML_TYPE, root);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) BeforeClass(org.junit.BeforeClass)

Aggregations

StringInputSource (org.exist.util.StringInputSource)72 Collection (org.exist.collections.Collection)57 Txn (org.exist.storage.txn.Txn)56 BrokerPool (org.exist.storage.BrokerPool)34 DBBroker (org.exist.storage.DBBroker)34 TransactionManager (org.exist.storage.txn.TransactionManager)27 XmldbURI (org.exist.xmldb.XmldbURI)17 Test (org.junit.Test)13 InputStream (java.io.InputStream)10 DocumentImpl (org.exist.dom.persistent.DocumentImpl)8 Sequence (org.exist.xquery.value.Sequence)7 CollectionConfigurationManager (org.exist.collections.CollectionConfigurationManager)5 EXistException (org.exist.EXistException)4 ManagedCollectionLock (org.exist.storage.lock.ManagedCollectionLock)4 LockException (org.exist.util.LockException)4 InputSource (org.xml.sax.InputSource)4 IOException (java.io.IOException)3 UnsynchronizedByteArrayOutputStream (org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)3 LockedDocument (org.exist.dom.persistent.LockedDocument)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3