cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r608967 - in /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax: XMLByteStreamCompiler.java XMLByteStreamInterpreter.java
Date Fri, 04 Jan 2008 19:39:52 GMT
Author: antonio
Date: Fri Jan  4 11:39:51 2008
New Revision: 608967

URL: http://svn.apache.org/viewvc?rev=608967&view=rev
Log:
Backporting refactoring from cocoon 2.2.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamInterpreter.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java?rev=608967&r1=608966&r2=608967&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamCompiler.java
Fri Jan  4 11:39:51 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,26 +17,16 @@
 package org.apache.cocoon.components.sax;
 
 import org.apache.avalon.excalibur.pool.Recyclable;
-import org.apache.avalon.framework.CascadingRuntimeException;
-import org.xml.sax.Attributes;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
 
-import java.util.HashMap;
 
 /**
  * This a simple xml compiler which outputs a byte array.
+ * If you want to reuse this instance, make sure to call {@link #recycle()}
+ * inbetween two compilation tasks.
  *
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
- * @version CVS $Id$
+ * @version $Id$
  */
-
-public final class XMLByteStreamCompiler implements XMLSerializer, Recyclable {
-
-    private HashMap map;
-    private int mapCount;
+public final class XMLByteStreamCompiler extends AbstractXMLByteStreamCompiler implements
XMLSerializer, Recyclable {
 
     /** The buffer for the compile xml byte stream. */
     private byte buf[];
@@ -48,51 +38,25 @@
 
 
     public XMLByteStreamCompiler() {
-        this.map = new HashMap();
+        super();
         this.bufCountAverage = 2000;
         this.initOutput();
     }
 
     private void initOutput() {
-        this.mapCount = 0;
-        this.map.clear();
         this.buf = new byte[bufCountAverage];
-        this.buf[0] = (byte)'C';
-        this.buf[1] = (byte)'X';
-        this.buf[2] = (byte)'M';
-        this.buf[3] = (byte)'L';
-        this.buf[4] = (byte)1;
-        this.buf[5] = (byte)0;
-        this.bufCount = 6;
+        this.bufCount = 0;
     }
 
     public void recycle() {
         bufCountAverage = (bufCountAverage + bufCount) / 2;
-        this.initOutput();
+        initOutput();
+        super.recycle();
     }
 
-    private static final int START_DOCUMENT         = 0;
-    private static final int END_DOCUMENT           = 1;
-    private static final int START_PREFIX_MAPPING   = 2;
-    private static final int END_PREFIX_MAPPING     = 3;
-    private static final int START_ELEMENT          = 4;
-    private static final int END_ELEMENT            = 5;
-    private static final int CHARACTERS             = 6;
-    private static final int IGNORABLE_WHITESPACE   = 7;
-    private static final int PROCESSING_INSTRUCTION = 8;
-    private static final int COMMENT                = 9;
-    private static final int LOCATOR                = 10;
-    private static final int START_DTD              = 11;
-    private static final int END_DTD                = 12;
-    private static final int START_CDATA            = 13;
-    private static final int END_CDATA              = 14;
-    private static final int SKIPPED_ENTITY         = 15;
-    private static final int START_ENTITY           = 16;
-    private static final int END_ENTITY             = 17;
-
 
     public Object getSAXFragment() {
-        if (this.bufCount == 6) { // no event arrived yet
+        if (this.bufCount == 0) { // no event arrived yet
             return null;
         }
         byte newbuf[] = new byte[this.bufCount];
@@ -100,281 +64,7 @@
         return newbuf;
     }
 
-    public void startDocument() throws SAXException {
-        this.writeEvent(START_DOCUMENT);
-    }
-
-    public void endDocument() throws SAXException {
-        this.writeEvent(END_DOCUMENT);
-    }
-
-    public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws
SAXException {
-        this.writeEvent(START_PREFIX_MAPPING);
-        this.writeString(prefix);
-        this.writeString(uri);
-    }
-
-    public void endPrefixMapping(String prefix) throws SAXException {
-       this.writeEvent(END_PREFIX_MAPPING);
-       this.writeString(prefix);
-    }
-
-    public void startElement(String namespaceURI, String localName, String qName, Attributes
atts) throws SAXException {
-        int length = atts.getLength();
-        this.writeEvent(START_ELEMENT);
-        this.writeAttributes(length);
-        for (int i = 0; i < length; i++) {
-            this.writeString(atts.getURI(i));
-            this.writeString(atts.getLocalName(i));
-            this.writeString(atts.getQName(i));
-            this.writeString(atts.getType(i));
-            this.writeString(atts.getValue(i));
-         }
-         this.writeString((namespaceURI == null ? "" : namespaceURI));
-         this.writeString(localName);
-         this.writeString(qName);
-     }
-
-    public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
-        this.writeEvent(END_ELEMENT);
-        this.writeString((namespaceURI == null ? "" : namespaceURI));
-        this.writeString(localName);
-        this.writeString(qName);
-    }
-
-    public void characters(char[] ch, int start, int length) throws SAXException {
-        this.writeEvent(CHARACTERS);
-        this.writeChars(ch, start, length);
-    }
-
-    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
{
-        this.writeEvent(IGNORABLE_WHITESPACE);
-        this.writeChars(ch, start, length);
-    }
-
-    public void processingInstruction(String target, String data) throws SAXException {
-        this.writeEvent(PROCESSING_INSTRUCTION);
-        this.writeString(target);
-        this.writeString(data);
-    }
-
-    public void setDocumentLocator(Locator locator) {
-        try {
-            this.writeEvent(LOCATOR);
-            String publicId = locator.getPublicId();
-            String systemId = locator.getSystemId();
-            this.writeString(publicId!=null?publicId:"");
-            this.writeString(systemId!=null?systemId:"");
-            this.write(locator.getLineNumber());
-            this.write(locator.getColumnNumber());
-        } catch (Exception e) {
-             throw new CascadingRuntimeException("Error while handling locator", e);
-        }
-    }
-
-    public void skippedEntity(java.lang.String name) throws SAXException {
-        this.writeEvent(SKIPPED_ENTITY);
-        this.writeString(name);
-    }
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void startDTD(String name, String publicId, String systemId) throws SAXException
{
-        this.writeEvent(START_DTD);
-        this.writeString(name);
-        this.writeString(publicId!=null?publicId:"");
-        this.writeString(systemId!=null?systemId:"");
-    }
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void endDTD() throws SAXException {
-        this.writeEvent(END_DTD);
-    }
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void startEntity(String name) throws SAXException {
-        this.writeEvent(START_ENTITY);
-        this.writeString(name);
-    }
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void endEntity(String name) throws SAXException {
-        this.writeEvent(END_ENTITY);
-        this.writeString(name);
-    }
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void startCDATA() throws SAXException {
-        this.writeEvent(START_CDATA);
-    }
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void endCDATA() throws SAXException {
-        this.writeEvent(END_CDATA);
-    }
-
-
-    /**
-     * SAX Event Handling: LexicalHandler
-     */
-    public void comment(char ary[], int start, int length) throws SAXException {
-        try {
-            this.writeEvent(COMMENT);
-            this.writeChars(ary, start, length);
-        } catch (Exception e) {
-            throw new SAXException(e);
-        }
-    }
-
-    public final void writeEvent( final int event) {
-        this.write(event);
-    }
-
-    public final void writeAttributes( final int attributes) throws SAXException {
-        if (attributes > 0xFFFF) throw new SAXException("Too many attributes");
-        this.write((attributes >>> 8) & 0xFF);
-        this.write((attributes >>> 0) & 0xFF);
-    }
-
-    public final void writeString( final String str) throws SAXException {
-        Integer index = (Integer) map.get(str);
-        if (index == null) {
-            map.put(str, new Integer(mapCount++));
-            int length = str.length();
-            this.writeChars(str.toCharArray(), 0, length);
-        }
-        else {
-            int i = index.intValue();
-
-            if (i > 0xFFFF) throw new SAXException("Index too large");
-
-            this.write(((i >>> 8) & 0xFF) | 0x80);
-            this.write((i >>> 0) & 0xFF);
-        }
-    }
-
-    public final void writeChars( final char[] ch, final int start, final int length) {
-        int utflen = 0;
-        int c;
-
-        for (int i = 0; i < length; i++) {
-            c = ch[i + start];
-            if ((c >= 0x0001) && (c <= 0x007F)) {
-                utflen++;
-            }
-            else if (c > 0x07FF) {
-                utflen += 3;
-            }
-            else {
-                utflen += 2;
-            }
-        }
-
-        if (utflen >= 0x00007FFF) {
-            assure(bufCount + utflen + 6);
-
-            buf[bufCount++] = (byte)0x7F;
-            buf[bufCount++] = (byte)0xFF;
-
-            buf[bufCount++] = (byte) ((utflen >>> 24) & 0xFF);
-            buf[bufCount++] = (byte) ((utflen >>> 16) & 0xFF);
-            buf[bufCount++] = (byte) ((utflen >>>  8) & 0xFF);
-            buf[bufCount++] = (byte) ((utflen >>>  0) & 0xFF);
-        }
-        else {
-            assure(bufCount + utflen + 2);
-
-            buf[bufCount++] = (byte) ((utflen >>> 8) & 0xFF);
-            buf[bufCount++] = (byte) ((utflen >>> 0) & 0xFF);
-        }
-
-        for (int i = 0; i < length; i++) {
-            c = ch[i + start];
-            if ((c >= 0x0001) && (c <= 0x007F)) {
-                buf[bufCount++] = (byte) c;
-            }
-            else if (c > 0x07FF) {
-                buf[bufCount++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
-                buf[bufCount++] = (byte) (0x80 | ((c >>  6) & 0x3F));
-                buf[bufCount++] = (byte) (0x80 | ((c >>  0) & 0x3F));
-            }
-            else {
-                buf[bufCount++] = (byte) (0xC0 | ((c >>  6) & 0x1F));
-                buf[bufCount++] = (byte) (0x80 | ((c >>  0) & 0x3F));
-            }
-        }
-
-
-/*
-        if (length == 0) return;
-
-        assure( (int) (buf.length + length * utfRatioAverage) );
-
-        int utflentotal = 0;
-
-        bufCount += 2;
-        int bufStart = bufCount;
-
-        for (int i = 0; i < length; i++) {
-            int c = ch[i + start];
-            int l = bufCount-bufStart;
-
-            if (l+3 >= 0x7FFF) {
-                buf[bufStart-2] = (byte) ((l >>> 8) & 0xFF);
-                buf[bufStart-1] = (byte) ((l >>> 0) & 0xFF);
-                utflentotal += l;
-                bufCount += 2;
-                bufStart = bufCount;
-            }
-
-            if ((c >= 0x0001) && (c <= 0x007F)) {
-                assure(bufCount+1);
-                buf[bufCount++] = (byte)c;
-            }
-            else if (c > 0x07FF) {
-                assure(bufCount+3);
-                buf[bufCount++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
-                buf[bufCount++] = (byte) (0x80 | ((c >>  6) & 0x3F));
-                buf[bufCount++] = (byte) (0x80 | ((c >>  0) & 0x3F));
-            }
-            else {
-                assure(bufCount+2);
-                buf[bufCount++] = (byte) (0xC0 | ((c >>  6) & 0x1F));
-                buf[bufCount++] = (byte) (0x80 | ((c >>  0) & 0x3F));
-            }
-        }
-
-        int l = bufCount-bufStart;
-        buf[bufStart-2] = (byte) ((l >>> 8) & 0xFF);
-        buf[bufStart-1] = (byte) ((l >>> 0) & 0xFF);
-        utflentotal += l;
-
-        utfRatioAverage = (utfRatioAverage + (utflentotal / length) / 2);
-*/
-    }
-
-/*  JH (2003-11-20): seems to be never used
-
-    private void write( final byte[] b ) {
-        int newcount = this.bufCount + b.length;
-        assure(newcount);
-        System.arraycopy(b, 0, this.buf, this.bufCount, b.length);
-        this.bufCount = newcount;
-    }
-*/
-
-    private void write( final int b ) {
+    protected void write( final int b ) {
         int newcount = this.bufCount + 1;
         assure(newcount);
         this.buf[this.bufCount] = (byte)b;

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamInterpreter.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamInterpreter.java?rev=608967&r1=608966&r2=608967&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamInterpreter.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/sax/XMLByteStreamInterpreter.java
Fri Jan  4 11:39:51 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,290 +16,44 @@
  */
 package org.apache.cocoon.components.sax;
 
-import java.util.ArrayList;
-
-import org.apache.cocoon.xml.AbstractXMLProducer;
 import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
 
 /**
  * This a simple xml compiler which takes a byte array as input.
+ * If you want to reuse this interpreter make sure to call first {@link #recycle()}
+ * and then set the new consumer for the sax events.
  *
- * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
- * @version CVS $Id$
+ * @version $Id$
  */
+public final class XMLByteStreamInterpreter extends AbstractXMLByteStreamInterpreter implements
XMLDeserializer {
 
-public final class XMLByteStreamInterpreter extends AbstractXMLProducer implements XMLDeserializer
{
-
-    private static final int START_DOCUMENT         = 0;
-    private static final int END_DOCUMENT           = 1;
-    private static final int START_PREFIX_MAPPING   = 2;
-    private static final int END_PREFIX_MAPPING     = 3;
-    private static final int START_ELEMENT          = 4;
-    private static final int END_ELEMENT            = 5;
-    private static final int CHARACTERS             = 6;
-    private static final int IGNORABLE_WHITESPACE   = 7;
-    private static final int PROCESSING_INSTRUCTION = 8;
-    private static final int COMMENT                = 9;
-    private static final int LOCATOR                = 10;
-    private static final int START_DTD              = 11;
-    private static final int END_DTD                = 12;
-    private static final int START_CDATA            = 13;
-    private static final int END_CDATA              = 14;
-    private static final int SKIPPED_ENTITY         = 15;
-    private static final int START_ENTITY           = 16;
-    private static final int END_ENTITY             = 17;
-
-    private ArrayList list = new ArrayList();
     private byte[] input;
     private int currentPos;
 
     public void recycle() {
-        super.recycle();
-        this.list.clear();
         this.input = null;
+        super.recycle();
     }
 
     public void deserialize(Object saxFragment) throws SAXException {
         if (!(saxFragment instanceof byte[])) {
             throw new SAXException("XMLDeserializer needs byte array for deserialization.");
         }
-        this.list.clear();
         this.input = (byte[])saxFragment;
         this.currentPos = 0;
-        this.checkProlog();
-        this.parse();
-    }
-
-    private void parse() throws SAXException {
-        while ( currentPos < input.length) {
-            switch (this.readEvent()) {
-                case START_DOCUMENT:
-                    contentHandler.startDocument();
-                    break;
-                case END_DOCUMENT:
-                    contentHandler.endDocument();
-                    break;
-                case START_PREFIX_MAPPING:
-                    contentHandler.startPrefixMapping(this.readString(), this.readString());
-                    break;
-                case END_PREFIX_MAPPING:
-                    contentHandler.endPrefixMapping(this.readString());
-                    break;
-                case START_ELEMENT:
-                    int attributes = this.readAttributes();
-                    AttributesImpl atts = new AttributesImpl();
-                    for (int i = 0; i < attributes; i++) {
-                        atts.addAttribute(this.readString(), this.readString(), this.readString(),
this.readString(), this.readString());
-                    }
-                    contentHandler.startElement(this.readString(), this.readString(), this.readString(),
atts);
-                    break;
-                case END_ELEMENT:
-                    contentHandler.endElement(this.readString(), this.readString(), this.readString());
-                    break;
-                case CHARACTERS:
-                    char[] chars = this.readChars();
-                    int len = chars.length;
-                    while (len > 0 && chars[len-1]==0) len--;
-                    if (len > 0) contentHandler.characters(chars, 0, len);
-                    break;
-                case IGNORABLE_WHITESPACE:
-                    char[] spaces = this.readChars();
-                    len = spaces.length;
-                    while (len > 0 && spaces[len-1]==0) len--;
-                    if (len > 0) contentHandler.characters(spaces, 0, len);
-                    break;
-                case PROCESSING_INSTRUCTION:
-                    contentHandler.processingInstruction(this.readString(), this.readString());
-                    break;
-                case COMMENT:
-                    chars = this.readChars();
-                    if (this.lexicalHandler != null) {
-                        len = chars.length;
-                        while (len > 0 && chars[len-1]==0) len--;
-                        if (len > 0) lexicalHandler.comment(chars, 0, len);
-                    }
-                    break;
-                case LOCATOR:
-                    {
-                    String publicId = this.readString();
-                    String systemId = this.readString();
-                    int lineNumber = this.read();
-                    int columnNumber = this.read();
-                    org.xml.sax.helpers.LocatorImpl locator = new org.xml.sax.helpers.LocatorImpl();
-                    locator.setPublicId(publicId);
-                    locator.setSystemId(systemId);
-                    locator.setLineNumber(lineNumber);
-                    locator.setColumnNumber(columnNumber);
-                    contentHandler.setDocumentLocator(locator);
-                    }
-                    break;
-                case START_DTD:
-                    lexicalHandler.startDTD(this.readString(), 
-                                            this.readString(), 
-                                            this.readString());
-                    break;
-                case END_DTD:
-                    lexicalHandler.endDTD();
-                    break;
-                case START_CDATA:
-                    lexicalHandler.startCDATA();
-                    break;
-                case END_CDATA:
-                    lexicalHandler.endCDATA();
-                    break;
-                case SKIPPED_ENTITY:
-                    contentHandler.skippedEntity( this.readString() );
-                    break;
-                case START_ENTITY:
-                    lexicalHandler.startEntity( this.readString() );
-                    break;
-                case END_ENTITY:
-                    lexicalHandler.endEntity( this.readString() );
-                    break;
-                default:
-                    throw new SAXException ("parsing error: event not supported.");
-            }
-        }
-    }
-
-    private void checkProlog() throws SAXException {
-        int valid = 0;
-        if (this.read() == 'C') valid++;
-        if (this.read() == 'X') valid++;
-        if (this.read() == 'M') valid++;
-        if (this.read() == 'L') valid++;
-        if (this.read() == 1) valid++;
-        if (this.read() == 0) valid++;
-        if (valid != 6) throw new SAXException("Unrecognized file format.");
-    }
-
-    protected int readEvent() throws SAXException {
-        return this.read();
-    }
-
-    private int readAttributes() throws SAXException {
-        int ch1 = this.read();
-        int ch2 = this.read();
-        return ((ch1 << 8) + (ch2 << 0));
-    }
-
-    private String readString() throws SAXException {
-        int length = this.readWord();
-        int index = length & 0x00007FFF;
-        if (length >= 0x00008000) {
-            return (String) list.get(index);
-        }
-        else {
-            if (length == 0x00007FFF) {
-                length = this.readLong();
-            }
-            char[] chars = this.readChars(length);
-            int len = chars.length;
-            if (len > 0) {
-                while (chars[len-1]==0) len--;
-            }
-            String str;
-            if (len == 0) {
-                str = "";
-            } else {
-                str = new String(chars, 0, len);
-            }
-            list.add(str);
-            return str;
-        }
+        super.parse();
     }
 
-    /**
-     * The returned char array might contain any number of zero bytes
-     * at the end
-     */
-    private char[] readChars() throws SAXException {
-        int length = this.readWord();
-        if (length == 0x00007FFF) {
-            length = this.readLong();
-        }
-        return this.readChars(length);
-    }
-
-    private int read() throws SAXException {
+    protected int read() throws SAXException {
         if (currentPos >= input.length)
-            throw new SAXException("Reached end of input.");
+            return -1;
         return input[currentPos++] & 0xff;
     }
 
-    /**
-     * The returned char array might contain any number of zero bytes
-     * at the end
-     */
-    private char[] readChars(int len) throws SAXException {
-        char[] str = new char[len];
-        byte[] bytearr = new byte[len];
-        int c, char2, char3;
-        int count = 0;
-        int i = 0;
-
-        this.readBytes(bytearr);
-
-        while (count < len) {
-            c = bytearr[count] & 0xff;
-            switch (c >> 4) {
-                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
-                    // 0xxxxxxx
-                    count++;
-                    str[i++] = (char) c;
-                    break;
-                case 12: case 13:
-                    // 110x xxxx   10xx xxxx
-                    count += 2;
-                    char2 = bytearr[count-1];
-                    str[i++] = (char) (((c & 0x1F) << 6) | (char2 & 0x3F));
-                    break;
-                case 14:
-                    // 1110 xxxx  10xx xxxx  10xx xxxx
-                    count += 3;
-                    char2 = bytearr[count-2];
-                    char3 = bytearr[count-1];
-                    str[i++] = ((char)(((c & 0x0F) << 12) | ((char2 & 0x3F)
<< 6) | ((char3 & 0x3F) << 0)));
-                    break;
-                default:
-                    // 10xx xxxx,  1111 xxxx
-                    throw new SAXException("UTFDataFormatException");
-            }
-        }
-
-        return str;
-    }
-
-    private void readBytes(byte[] b) throws SAXException {
-        if (this.currentPos + b.length > this.input.length) {
-            // TC:
-            // >= prevents getting the last byte
-            // 0 1 2 3 4   input.length = 5
-            //     |_ currentPos = 2
-            // b.length = 3
-            // 2 + 3 > 5 ok
-            // 2 + 3 >= 5 wrong
-            // why has this worked before?
-            throw new SAXException("End of input reached.");
-        }
-        System.arraycopy(this.input, this.currentPos, b, 0, b.length);
-        this.currentPos += b.length;
-    }
-
-    private int readWord() throws SAXException {
-        int ch1 = this.read();
-        int ch2 = this.read();
-        return ((ch1 << 8) + (ch2 << 0));
-    }
-
-    private int readLong() throws SAXException {
-        int ch1 = this.read();
-        int ch2 = this.read();
-        int ch3 = this.read();
-        int ch4 = this.read();
-        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 <<
0));
+    protected int read(byte[] b) throws SAXException {
+        final int bytesRead = (this.currentPos + b.length > this.input.length ? this.input.length
- this.currentPos : b.length);
+        System.arraycopy(this.input, this.currentPos, b, 0, bytesRead);
+        this.currentPos += bytesRead;
+        return bytesRead;
     }
 }



Mime
View raw message