1 18 package org.ofbiz.content.openoffice; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 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 33 34 public class OpenOfficeByteArrayInputStream extends ByteArrayInputStream implements XInputStream, XSeekable { 35 36 public static final String 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 { 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 e) { 65 String 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 e) { 78 String 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 |