Search in sources :

Example 56 with UnsynchronizedByteArrayInputStream

use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.

the class MemtreeTest method getLastNode.

@Test
public void getLastNode() throws IOException, ParserConfigurationException, SAXException {
    final DocumentImpl doc;
    try (final InputStream is = new UnsynchronizedByteArrayInputStream(XML.getBytes(UTF_8))) {
        doc = parse(is);
    }
    assertEquals(26, doc.getLastNode());
}
Also used : UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) InputStream(java.io.InputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Test(org.junit.Test)

Example 57 with UnsynchronizedByteArrayInputStream

use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.

the class MemtreeTest method getAttributesCountFor.

@Test
public void getAttributesCountFor() throws IOException, ParserConfigurationException, SAXException {
    final DocumentImpl doc;
    try (final InputStream is = new UnsynchronizedByteArrayInputStream(XML.getBytes(UTF_8))) {
        doc = parse(is);
    }
    // attributes count of the document node
    assertEquals(0, doc.getAttributesCountFor(0));
    // attributes count of <!-- comment before doc 1 -->
    assertEquals(0, doc.getAttributesCountFor(1));
    // attributes count of <?pi-before-doc-1?>
    assertEquals(0, doc.getAttributesCountFor(2));
    // attributes count of <!-- comment before doc 2 -->
    assertEquals(0, doc.getAttributesCountFor(3));
    // attributes count of <?pi-before-doc-2?>
    assertEquals(0, doc.getAttributesCountFor(4));
    // attributes count of doc-element
    assertEquals(0, doc.getAttributesCountFor(5));
    // attributes count of doc-element/text()[1]
    assertEquals(0, doc.getAttributesCountFor(6));
    // attributes count of <!-- comment before e1 -->
    assertEquals(0, doc.getAttributesCountFor(7));
    // attributes count of doc-element/text()[2]
    assertEquals(0, doc.getAttributesCountFor(8));
    // attributes count of e1
    assertEquals(1, doc.getAttributesCountFor(9));
    // attributes count of e1/text()[1]
    assertEquals(0, doc.getAttributesCountFor(10));
    // attributes count of <?pi-before-e1_1?>
    assertEquals(0, doc.getAttributesCountFor(11));
    // attributes count of e1/text()[2]
    assertEquals(0, doc.getAttributesCountFor(12));
    // attributes count of e1_1
    assertEquals(1, doc.getAttributesCountFor(13));
    // attributes count of e1_1/text()[1]
    assertEquals(0, doc.getAttributesCountFor(14));
    // attributes count of e1/text()[3]
    assertEquals(0, doc.getAttributesCountFor(15));
    // attributes count of e1_2
    assertEquals(2, doc.getAttributesCountFor(16));
    // attributes count of e1_2/text()[1]
    assertEquals(0, doc.getAttributesCountFor(17));
    // attributes count of e1/text()[4]
    assertEquals(0, doc.getAttributesCountFor(18));
    // attributes count of doc-element/text()[3]
    assertEquals(0, doc.getAttributesCountFor(19));
    // attributes count of <!-- comment after e1 -->
    assertEquals(0, doc.getAttributesCountFor(20));
    // attributes count of doc-element/text()[4]
    assertEquals(0, doc.getAttributesCountFor(21));
    // attributes count of <?pi-after-doc-1?>
    assertEquals(0, doc.getAttributesCountFor(22));
    // attributes count of <!-- comment after doc 1 -->
    assertEquals(0, doc.getAttributesCountFor(23));
    // attributes count of <?pi-after-doc-2?>
    assertEquals(0, doc.getAttributesCountFor(24));
    // attributes count of <!-- comment after doc 2 -->
    assertEquals(0, doc.getAttributesCountFor(25));
    // attributes count of <?pi-after-doc-3?>
    assertEquals(0, doc.getAttributesCountFor(26));
}
Also used : UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) InputStream(java.io.InputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Test(org.junit.Test)

Example 58 with UnsynchronizedByteArrayInputStream

use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.

the class DocumentImplTest method checkNamespaces_xerces.

@Test
public void checkNamespaces_xerces() throws IOException, ParserConfigurationException, SAXException {
    final Document doc;
    try (final InputStream is = new UnsynchronizedByteArrayInputStream(DOC_WITH_NAMESPACES.getBytes(UTF_8))) {
        doc = parseXerces(is);
    }
    final Element elem = doc.getDocumentElement();
    final NamedNodeMap attrs = elem.getAttributes();
    assertEquals(2, attrs.getLength());
    int index = 0;
    final Attr attr1 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr1.getNodeType());
    assertTrue(attr1 instanceof AttrNSImpl);
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr1.getNamespaceURI());
    assertEquals(null, attr1.getPrefix());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getNodeName());
    assertEquals("http://exist-db.org/xquery/repo", attr1.getValue());
    final Attr attr2 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr2.getNodeType());
    assertTrue(attr2 instanceof AttrNSImpl);
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr2.getNamespaceURI());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getPrefix());
    assertEquals("repo", attr2.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":repo", attr2.getNodeName());
    assertEquals("http://exist-db.org/xquery/repo", attr2.getValue());
}
Also used : AttrNSImpl(org.apache.xerces.dom.AttrNSImpl) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) InputStream(java.io.InputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Test(org.junit.Test)

Example 59 with UnsynchronizedByteArrayInputStream

use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.

the class DocumentImplTest method checkNamespaces_saxon.

@Test
public void checkNamespaces_saxon() throws IOException, ParserConfigurationException, SAXException, IllegalAccessException, InstantiationException, ClassNotFoundException {
    final Document doc;
    try (final InputStream is = new UnsynchronizedByteArrayInputStream(DOC_WITH_NAMESPACES.getBytes(UTF_8))) {
        doc = parseSaxon(is);
    }
    final Element elem = doc.getDocumentElement();
    final NamedNodeMap attrs = elem.getAttributes();
    assertEquals(3, attrs.getLength());
    int index = 0;
    final Attr attr1 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr1.getNodeType());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr1.getNamespaceURI());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr1.getPrefix());
    assertEquals(XMLConstants.XML_NS_PREFIX, attr1.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":" + XMLConstants.XML_NS_PREFIX, attr1.getNodeName());
    assertEquals(XMLConstants.XML_NS_URI, attr1.getValue());
    final Attr attr2 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr2.getNodeType());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr2.getNamespaceURI());
    assertEquals(null, attr2.getPrefix());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr2.getNodeName());
    assertEquals("http://exist-db.org/xquery/repo", attr2.getValue());
    final Attr attr3 = (Attr) attrs.item(index++);
    assertEquals(Node.ATTRIBUTE_NODE, attr3.getNodeType());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr3.getNamespaceURI());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr3.getPrefix());
    assertEquals("repo", attr3.getLocalName());
    assertEquals(XMLConstants.XMLNS_ATTRIBUTE + ":repo", attr3.getNodeName());
    assertEquals("http://exist-db.org/xquery/repo", attr3.getValue());
}
Also used : UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) InputStream(java.io.InputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Test(org.junit.Test)

Example 60 with UnsynchronizedByteArrayInputStream

use of org.apache.commons.io.input.UnsynchronizedByteArrayInputStream in project exist by eXist-db.

the class ConfigurableTest method notSimple.

@Test
public void notSimple() throws Exception {
    InputStream is = new UnsynchronizedByteArrayInputStream(config3.getBytes(UTF_8));
    Configuration config = Configurator.parse(is);
    ConfigurableObject2 object = new ConfigurableObject2(config);
    assertEquals("a", object.some);
    assertEquals(Integer.valueOf(5), object.someInteger);
    assertTrue(object.simpleInteger == 5);
    assertTrue(object.defaultInteger == 3);
    assertTrue(object.someboolean);
    assertFalse(object.someBoolean);
    assertEquals("cool", object.sp.name);
}
Also used : UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) InputStream(java.io.InputStream) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Test(org.junit.Test)

Aggregations

UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)114 InputStream (java.io.InputStream)102 Test (org.junit.Test)93 MarkShieldInputStream (org.apache.commons.io.input.MarkShieldInputStream)31 UnsynchronizedByteArrayOutputStream (org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream)10 IOException (java.io.IOException)8 FilterInputStream (java.io.FilterInputStream)7 CachingFilterInputStream (org.exist.util.io.CachingFilterInputStream)7 XMLResource (org.xmldb.api.modules.XMLResource)6 DBBroker (org.exist.storage.DBBroker)5 Txn (org.exist.storage.txn.Txn)5 Element (org.w3c.dom.Element)4 Collection (org.xmldb.api.base.Collection)4 NodeProxy (org.exist.dom.persistent.NodeProxy)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 DigestInputStream (org.exist.util.crypto.digest.DigestInputStream)3 Base64BinaryValueType (org.exist.xquery.value.Base64BinaryValueType)3 BooleanValue (org.exist.xquery.value.BooleanValue)3 DoubleValue (org.exist.xquery.value.DoubleValue)3 StringValue (org.exist.xquery.value.StringValue)3