Package org.codehaus.stax2

Examples of org.codehaus.stax2.XMLInputFactory2


    }

    private void writeFileContentsAsXML(OutputStream out)
        throws IOException, XMLStreamException
    {
        XMLStreamWriter2 sw = (XMLStreamWriter2) _xmlOutputFactory.createXMLStreamWriter(out);
        sw.writeStartDocument();
        sw.writeStartElement("files");
        byte[] buffer = new byte[4000];
        MessageDigest md;
        try {
            md = MessageDigest.getInstance(DIGEST_TYPE);
        } catch (Exception e) { // no such hash type?
            throw new IOException(e);
        }

        for (File f : _downloadableFiles.listFiles()) {
            sw.writeStartElement("file");
            sw.writeAttribute("name", f.getName());
            sw.writeAttribute("checksumType", DIGEST_TYPE);
            FileInputStream fis = new FileInputStream(f);
            int count;
            while ((count = fis.read(buffer)) != -1) {
                md.update(buffer, 0, count);
                sw.writeBinary(buffer, 0, count);
            }
            fis.close();
            sw.writeEndElement(); // file
            sw.writeStartElement("checksum");
            sw.writeBinaryAttribute("", "", "value", md.digest());
            sw.writeEndElement(); // checksum
        }
        sw.writeEndElement(); // files
        sw.writeEndDocument();
        sw.close();
    }
View Full Code Here


        assertTokenType(DTD, evt.getEventType());

        DTD dtd = (DTD) evt;
        List<?> nots = dtd.getNotations();
        assertEquals(1, nots.size());
        NotationDeclaration2 notDecl = (NotationDeclaration2) nots.get(0);

        assertEquals(URI, notDecl.getBaseURI());
    }
View Full Code Here

                    System.out.print("  ("+entCount+" entities, "+notCount
                                       +" notations), sysid ");
                    if (notCount > 0) {
                        System.out.println();
                        for (int i = 0; i < notCount; ++i) {
                            NotationDeclaration2 nd = (NotationDeclaration2)notations.get(i);
                            System.out.println(" notation '"+nd.getName()+"', base: ["+nd.getBaseURI()+"]");
                        }
                    }
                    System.out.print(", declaration = <<");
                    System.out.print(text);
                    System.out.println(">>");
View Full Code Here

            try {
    /* 11-Nov-2008, TSa: Let's add optimized handling for byte-block
     *   source
     */
    if (src instanceof Stax2ByteArraySource) {
        Stax2ByteArraySource bas = (Stax2ByteArraySource) src;
        bs = StreamBootstrapper.getInstance(pubId, sysId, bas.getBuffer(), bas.getBufferStart(), bas.getBufferEnd());
    } else {
        in = ss.constructInputStream();
        if (in == null) {
      r = ss.constructReader();
        }
View Full Code Here

        boolean autoCloseInput;

        InputBootstrapper bs = null;

        if (src instanceof Stax2Source) {
            Stax2Source ss = (Stax2Source) src;
            sysId = ss.getSystemId();
            pubId = ss.getPublicId();
            encoding = ss.getEncoding();

            try {
    /* 11-Nov-2008, TSa: Let's add optimized handling for byte-block
     *   source
     */
    if (src instanceof Stax2ByteArraySource) {
        Stax2ByteArraySource bas = (Stax2ByteArraySource) src;
        bs = StreamBootstrapper.getInstance(pubId, sysId, bas.getBuffer(), bas.getBufferStart(), bas.getBufferEnd());
    } else {
        in = ss.constructInputStream();
        if (in == null) {
      r = ss.constructReader();
        }
    }
            } catch (IOException ioe) {
                throw new WstxIOException(ioe);
            }
            /* Caller has no direct access to stream/reader, Woodstox
             * owns it and thus has to close too
             */
            autoCloseInput = true;
        } else  if (src instanceof StreamSource) {
            StreamSource ss = (StreamSource) src;
            sysId = ss.getSystemId();
            pubId = ss.getPublicId();
            in = ss.getInputStream();
            if (in == null) {
                r = ss.getReader();
            }
            /* Caller still has access to stream/reader; no need to
             * force auto-close-input
             */
            autoCloseInput = cfg.willAutoCloseInput();
        } else if (src instanceof SAXSource) {
            SAXSource ss = (SAXSource) src;
            /* 28-Jan-2006, TSa: Not a complete implementation, but maybe
             *   even this might help...
             */
            sysId = ss.getSystemId();
            InputSource isrc = ss.getInputSource();
            if (isrc != null) {
                encoding = isrc.getEncoding();
                in = isrc.getByteStream();
                if (in == null) {
                    r = isrc.getCharacterStream();
View Full Code Here

    }

    public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter)
        throws XMLStreamException
    {
        Stax2FilteredStreamReader fr = new Stax2FilteredStreamReader(reader, filter);
        /* [WSTX-111] As per Stax 1.0 TCK, apparently the filtered
         *   reader is expected to be automatically forwarded to the first
         *   acceptable event. This is different from the way RI works, but
         *   since specs don't say anything about filtered readers, let's
         *   consider TCK to be "more formal" for now, and implement that
         *   behavior.
         */
        if (!filter.accept(fr)) { // START_DOCUMENT ok?
            // Ok, nope, this should do the trick:
            fr.next();
        }
        return fr;
    }
View Full Code Here

    /////////////////////////////////////////////
     */

    public Attribute constructAttr(String[] raw, int rawIndex, boolean isDef)
    {
        return new AttributeEventImpl(mLocation, raw[rawIndex], raw[rawIndex+1],
                                      raw[rawIndex+2], raw[rawIndex+3], isDef);
    }
View Full Code Here

    // // // Filtered reader factory methods

    public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter)
    {
        return new Stax2FilteredEventReader(Stax2EventReaderAdapter.wrapIfNecessary(reader), filter);
    }
View Full Code Here

             * data:
             */
            int ptr = 0;
            do {
                int chunkLen = 1 + (r.nextInt() & 0x7);
                AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, ptr, chunkLen);
                ptr += chunkLen;
                int len = enc.encodeMore(buffer, 0, buffer.length);
                b64.append(buffer, 0, len);
            } while (b64.length() < SIZE);
            // And then create document, with split content
           
            final int byteLen = ptr;
View Full Code Here

        // So first we'll encode 1 to 6 bytes as base64
        for (int bv = 0; bv < sPaddingVariants.length; ++bv) {
            Base64Variant b64variant = sPaddingVariants[bv];
            for (int i = 1; i <= data.length; ++i) {
                AsciiValueEncoder enc = new ValueEncoderFactory().getEncoder(b64variant, data, 0, i);
                char[] cbuf = new char[20];
                int clen = enc.encodeMore(cbuf, 0, cbuf.length);
               
                // and use all byte last 1, 2 or 3 chars
                for (int j = 1; j <= 3; ++j) {
                    int testLen = clen-j;
                    StringBuffer sb = new StringBuffer();
View Full Code Here

TOP

Related Classes of org.codehaus.stax2.XMLInputFactory2

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.