001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.content.openoffice;
019:
020: import java.io.ByteArrayInputStream;
021: import java.io.IOException;
022:
023: import com.sun.star.io.XSeekable;
024: import com.sun.star.io.XInputStream;
025: import com.sun.star.io.BufferSizeExceededException;
026: import com.sun.star.io.NotConnectedException;
027:
028: /**
029: * OpenOfficeByteArrayInputStream Class
030: */
031:
032: public class OpenOfficeByteArrayInputStream extends
033: ByteArrayInputStream implements XInputStream, XSeekable {
034:
035: public static final String module = OpenOfficeByteArrayInputStream.class
036: .getName();
037:
038: public OpenOfficeByteArrayInputStream(byte[] bytes) {
039: super (bytes);
040: }
041:
042: public long getPosition() throws com.sun.star.io.IOException {
043: return this .pos;
044: }
045:
046: public long getLength() throws com.sun.star.io.IOException {
047: return this .count;
048: }
049:
050: public void seek(long pos1) throws com.sun.star.io.IOException,
051: IllegalArgumentException {
052: this .pos = (int) pos1;
053: }
054:
055: public void skipBytes(int pos1) throws BufferSizeExceededException,
056: NotConnectedException, com.sun.star.io.IOException {
057: skip(pos1);
058: }
059:
060: public void closeInput() throws NotConnectedException,
061: com.sun.star.io.IOException {
062:
063: try {
064: close();
065: } catch (IOException e) {
066: String errMsg = e.getMessage();
067: throw new com.sun.star.io.IOException(errMsg, this );
068: }
069:
070: }
071:
072: public int readBytes(byte[][] buf, int pos2)
073: throws BufferSizeExceededException, NotConnectedException,
074: com.sun.star.io.IOException {
075:
076: int bytesRead = 0;
077: byte[] buf2 = new byte[pos2];
078: try {
079: bytesRead = super .read(buf2);
080: } catch (IOException e) {
081: String errMsg = e.getMessage();
082: throw new com.sun.star.io.IOException(errMsg, this );
083: }
084:
085: if (bytesRead > 0) {
086: if (bytesRead < pos2) {
087: byte[] buf3 = new byte[bytesRead];
088: System.arraycopy(buf2, 0, buf3, 0, bytesRead);
089: buf[0] = buf3;
090: } else {
091: buf[0] = buf2;
092: }
093: } else {
094: buf[0] = new byte[0];
095: }
096: return bytesRead;
097: }
098:
099: public int readSomeBytes(byte[][] buf, int pos2)
100: throws BufferSizeExceededException, NotConnectedException,
101: com.sun.star.io.IOException {
102: return readBytes(buf, pos2);
103: }
104: }
|