|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ByteArrayInput.java | 50% | 57.1% | 60% | 57.1% |
|
||||||||||||||
| 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: ByteArrayInput.java 571951 2007-09-02 10:53:51Z vgritsenko $ | |
| 18 | */ | |
| 19 | ||
| 20 | package org.apache.xindice.util; | |
| 21 | ||
| 22 | import java.io.ByteArrayInputStream; | |
| 23 | import java.io.IOException; | |
| 24 | import java.io.InputStream; | |
| 25 | ||
| 26 | /** | |
| 27 | * ByteArrayInput is a wrapper around ByteArrayInputStream that allows read | |
| 28 | * access to the current position pointer. | |
| 29 | * | |
| 30 | * @version $Revision: 571951 $, $Date: 2007-09-02 03:53:51 -0700 (Sun, 02 Sep 2007) $ | |
| 31 | */ | |
| 32 | public final class ByteArrayInput extends ByteArrayInputStream { | |
| 33 | ||
| 34 | 0 | public ByteArrayInput(byte[] buf) { |
| 35 | 0 | super(buf); |
| 36 | } | |
| 37 | ||
| 38 | 721308 | public ByteArrayInput(byte[] buf, int pos, int length) { |
| 39 | 721308 | super(buf, pos, length); |
| 40 | } | |
| 41 | ||
| 42 | /** | |
| 43 | * getPos returns the current read position in the array. This value is not | |
| 44 | * a relative offset from the start of the original stream, but an absolute | |
| 45 | * position in the array itself. | |
| 46 | * | |
| 47 | * @return The Array Position | |
| 48 | */ | |
| 49 | 416198 | public int getPos() { |
| 50 | 416198 | return pos; |
| 51 | } | |
| 52 | ||
| 53 | /** | |
| 54 | * setPos sets the current read position in the array. This value is not a | |
| 55 | * relative offset from the start of the original stream, but an absolute | |
| 56 | * position in the array itself. As such, you can seek back to a position | |
| 57 | * before the originating position of the InputStream. | |
| 58 | * | |
| 59 | * @param pos The Array Position | |
| 60 | * @throws IOException if the position is out of range | |
| 61 | */ | |
| 62 | 416198 | public void setPos(int pos) throws IOException { |
| 63 | 416198 | if (pos >= 0 && pos < buf.length) { |
| 64 | 416198 | this.pos = pos; |
| 65 | } else { | |
| 66 | 0 | throw new IOException("setPos position out of bounds"); |
| 67 | } | |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * getInputStream returns a newly created ByteArrayInput based on this | |
| 72 | * instance's data and current position. This is a good alternative to | |
| 73 | * mark and reset because it allows multiple threads to safely access | |
| 74 | * the byte array at one time. | |
| 75 | * | |
| 76 | * @return The New ByteArrayInput object | |
| 77 | */ | |
| 78 | 0 | public InputStream getInputStream() { |
| 79 | 0 | return new ByteArrayInput(buf, pos, count); |
| 80 | } | |
| 81 | } |
|
||||||||||