Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 219   Methods: 6
NCLOC: 115   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XMLCompressedInput.java 16.7% 58.7% 83.3% 55.1%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: XMLCompressedInput.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.xml;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.w3c.dom.Node;
 25   
 26    import java.io.DataInputStream;
 27    import java.io.IOException;
 28    import java.io.InputStream;
 29   
 30    /**
 31    * XMLCompressedInput is an InputStream extension that provides functions for
 32    * reading type from a Xindice Compressed XML Stream.
 33    *
 34    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 35    */
 36    public class XMLCompressedInput extends DataInputStream {
 37   
 38    private static final Log log = LogFactory.getLog(XMLCompressedInput.class);
 39   
 40    private byte signature = 0;
 41    // Not used: private SymbolTable st = null;
 42   
 43  721308 public XMLCompressedInput(InputStream is, SymbolTable st) {
 44  721308 super(is);
 45    // this.st = st;
 46    }
 47   
 48    /**
 49    * readSignature reads a Node signature byte from the input stream.
 50    *
 51    * @return The signature
 52    * @throws IOException if an IOException occurs
 53    */
 54  1094122 public final byte readSignature() throws IOException {
 55  1094122 signature = readByte();
 56  1094122 return signature;
 57    }
 58   
 59    /**
 60    * getSignature returns the most recently read signature byte from the
 61    * input stream.
 62    *
 63    * @return The signature
 64    */
 65  0 public final byte getSignature() {
 66  0 return signature;
 67    }
 68   
 69    /**
 70    * getNodeType resolves and returns the DOM Node type from the given
 71    * Xindice compressed signature.
 72    *
 73    * @return The DOM Node type
 74    */
 75  1813550 public final short getNodeType() {
 76  1813550 byte type = (byte) (signature & 0xC0);
 77  1813550 switch (type) {
 78   
 79  715185 case Signatures.NODE_TEXT:
 80  715185 type = (byte) (signature & 0x20);
 81  715185 if (type == Signatures.TEXT_TEXT) {
 82  715185 return Node.TEXT_NODE;
 83    } else {
 84  0 return Node.ENTITY_REFERENCE_NODE;
 85    }
 86   
 87  1092831 case Signatures.NODE_ELEM:
 88  1092831 return Node.ELEMENT_NODE;
 89   
 90  5316 case Signatures.NODE_PROC:
 91  5316 return Node.PROCESSING_INSTRUCTION_NODE;
 92   
 93  218 case Signatures.NODE_DECL:
 94  218 switch ((byte) (signature & 0x3C)) {
 95   
 96  8 case Signatures.DECL_CDATA:
 97  8 return Node.CDATA_SECTION_NODE;
 98   
 99  0 case Signatures.DECL_ENTITY:
 100  0 return Node.ENTITY_NODE;
 101   
 102  210 case Signatures.DECL_COMMENT:
 103  210 return Node.COMMENT_NODE;
 104   
 105  0 case Signatures.DECL_DOCTYPE:
 106  0 return Node.DOCUMENT_TYPE_NODE;
 107   
 108  0 case Signatures.DECL_NOTATION:
 109  0 return Node.NOTATION_NODE;
 110   
 111  0 default:
 112  0 return Signatures.Unknown;
 113    }
 114   
 115  0 default:
 116  0 if (log.isWarnEnabled()) {
 117  0 log.warn("invalid signature : " + type);
 118    }
 119   
 120    }
 121   
 122  0 return Signatures.Unknown;
 123    }
 124   
 125    /**
 126    * readContentSize reads the size of the upcoming content from the Stream,
 127    * based on the object signature that is provided.
 128    *
 129    * @return The Content Size
 130    * @throws IOException if an IOException occurs
 131    */
 132  1091418 public final int readContentSize() throws IOException {
 133  1091418 int sizeType = 0;
 134   
 135  1091418 short nodeType = getNodeType();
 136  1091418 switch (nodeType) {
 137   
 138  476785 case Node.TEXT_NODE:
 139  611866 case Node.ELEMENT_NODE:
 140  1088651 sizeType = (byte) ((signature & 0x0C) >>> 0x2);
 141  1088651 break;
 142   
 143  2658 case Node.PROCESSING_INSTRUCTION_NODE:
 144  105 case Node.COMMENT_NODE:
 145  4 case Node.CDATA_SECTION_NODE:
 146  2767 sizeType = Signatures.SIZE_INT;
 147  2767 break;
 148   
 149  0 case Node.NOTATION_NODE:
 150  0 sizeType = (byte) (signature & 0x03);
 151  0 break;
 152   
 153  0 default:
 154  0 if (log.isWarnEnabled()) {
 155  0 log.warn("invalid node type : " + nodeType);
 156    }
 157    }
 158   
 159  1091418 switch (sizeType) {
 160   
 161  1073319 case Signatures.SIZE_BYTE:
 162  1073319 return readByte();
 163   
 164  15332 case Signatures.SIZE_SHORT:
 165  15332 return readShort();
 166   
 167  2767 case Signatures.SIZE_INT:
 168  2767 return readInt();
 169   
 170  0 case Signatures.SIZE_NONE:
 171    // Do Nothing
 172  0 break;
 173   
 174  0 default:
 175  0 if (log.isWarnEnabled()) {
 176  0 log.warn("invalid size : " + sizeType);
 177    }
 178    }
 179   
 180  0 return 0;
 181    }
 182   
 183    /**
 184    * readAttributeCount reads the count of the upcoming Attributes from the
 185    * Stream based on the object signature that is provided.
 186    *
 187    * @return The Content Size
 188    * @throws IOException if an IOException occurs
 189    */
 190  305934 public final int readAttributeCount() throws IOException {
 191  305934 int countType = 0;
 192  305934 if (getNodeType() == Node.ELEMENT_NODE) {
 193  305934 countType = (byte) (signature & 0x03);
 194    }
 195   
 196  305934 switch (countType) {
 197   
 198  165296 case Signatures.SIZE_BYTE:
 199  165296 return readByte();
 200   
 201  0 case Signatures.SIZE_SHORT:
 202  0 return readShort();
 203   
 204  0 case Signatures.SIZE_INT:
 205  0 return readInt();
 206   
 207  140638 case Signatures.SIZE_NONE:
 208    // Do Nothing
 209  140638 break;
 210   
 211  0 default:
 212  0 if (log.isWarnEnabled()) {
 213  0 log.warn("invalid signature type : " + countType);
 214    }
 215    }
 216   
 217  140638 return 0;
 218    }
 219    }