KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > content > openoffice > OpenOfficeByteArrayInputStream


1 /*
2  * $Id: $
3  *
4  * Copyright 2005-2006 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7  * use this file except in compliance with the License. You may obtain a copy of
8  * the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */

18 package org.ofbiz.content.openoffice;
19
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 import com.sun.star.io.XSeekable;
24 import com.sun.star.io.XInputStream;
25 import com.sun.star.io.BufferSizeExceededException;
26 import com.sun.star.io.NotConnectedException;
27
28 /**
29  * OpenOfficeByteArrayInputStream Class
30  *
31  * @author <a HREF="mailto:byersa@automationgroups.com">Al Byers</a>
32  */

33
34 public class OpenOfficeByteArrayInputStream extends ByteArrayInputStream JavaDoc implements XInputStream, XSeekable {
35     
36     public static final String JavaDoc module = OpenOfficeByteArrayInputStream.class.getName();
37     
38     public OpenOfficeByteArrayInputStream(byte [] bytes) {
39         super(bytes);
40     }
41     
42     
43     public long getPosition() throws com.sun.star.io.IOException {
44         return this.pos;
45     }
46     
47     public long getLength() throws com.sun.star.io.IOException {
48         return this.count;
49     }
50     
51     public void seek(long pos1) throws com.sun.star.io.IOException, IllegalArgumentException JavaDoc {
52         this.pos = (int)pos1;
53     }
54
55     public void skipBytes(int pos1) throws BufferSizeExceededException,
56                                              NotConnectedException, com.sun.star.io.IOException {
57         skip(pos1);
58     }
59
60     public void closeInput() throws NotConnectedException, com.sun.star.io.IOException {
61         
62         try {
63             close();
64         } catch( IOException JavaDoc e) {
65             String JavaDoc errMsg = e.getMessage();
66             throw new com.sun.star.io.IOException( errMsg, this );
67         }
68         
69     }
70     
71     public int readBytes(byte [][]buf, int pos2) throws BufferSizeExceededException, NotConnectedException, com.sun.star.io.IOException {
72         
73         int bytesRead = 0;
74         byte [] buf2 = new byte[pos2];
75         try {
76             bytesRead = super.read(buf2);
77         } catch( IOException JavaDoc e) {
78             String JavaDoc errMsg = e.getMessage();
79             throw new com.sun.star.io.IOException( errMsg, this );
80         }
81         
82         if (bytesRead > 0) {
83             if (bytesRead < pos2) {
84                 byte [] buf3 = new byte[bytesRead];
85                 System.arraycopy(buf2, 0, buf3, 0, bytesRead);
86                 buf[0] = buf3;
87             } else {
88                 buf[0] = buf2;
89             }
90         } else {
91             buf[0] = new byte[0];
92         }
93         return bytesRead;
94     }
95
96     public int readSomeBytes(byte [][]buf, int pos2) throws BufferSizeExceededException, NotConnectedException, com.sun.star.io.IOException {
97         return readBytes(buf, pos2);
98     }
99 }
100
Popular Tags