1 package complex
.storages
;
3 import com
.sun
.star
.uno
.XInterface
;
4 import com
.sun
.star
.lang
.XMultiServiceFactory
;
5 import com
.sun
.star
.lang
.XSingleServiceFactory
;
7 import com
.sun
.star
.bridge
.XUnoUrlResolver
;
8 import com
.sun
.star
.uno
.UnoRuntime
;
9 import com
.sun
.star
.uno
.XInterface
;
11 import com
.sun
.star
.io
.XStream
;
12 import com
.sun
.star
.io
.XInputStream
;
13 import com
.sun
.star
.io
.XOutputStream
;
14 import com
.sun
.star
.io
.XTruncate
;
15 import com
.sun
.star
.io
.XSeekable
;
18 public class BorderedStream
19 implements XStream
, XInputStream
, XOutputStream
, XTruncate
, XSeekable
26 public BorderedStream( int nMaxSize
)
28 m_nMaxSize
= nMaxSize
;
31 m_pBytes
= new byte[m_nMaxSize
];
38 // ----------------------------------------------------------
39 public synchronized XInputStream
getInputStream()
40 throws com
.sun
.star
.uno
.RuntimeException
42 return (XInputStream
)UnoRuntime
.queryInterface( XInputStream
.class, this );
45 // ----------------------------------------------------------
46 public synchronized XOutputStream
getOutputStream()
47 throws com
.sun
.star
.uno
.RuntimeException
49 return (XOutputStream
)UnoRuntime
.queryInterface( XOutputStream
.class, this );
56 // ----------------------------------------------------------
57 public synchronized int readBytes( byte[][] aData
, int nBytesToRead
)
58 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.BufferSizeExceededException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
61 if ( m_pBytes
!= null && nBytesToRead
> 0 )
63 int nAvailable
= m_nCurSize
- m_nCurPos
;
64 if ( nBytesToRead
> nAvailable
)
65 nBytesToRead
= nAvailable
;
67 aData
[0] = new byte[nBytesToRead
];
68 for ( int nInd
= 0; nInd
< nBytesToRead
; nInd
++ )
69 aData
[0][nInd
] = m_pBytes
[m_nCurPos
+nInd
];
76 aData
[0] = new byte[0];
82 // ----------------------------------------------------------
83 public synchronized int readSomeBytes( byte[][] aData
, int nMaxBytesToRead
)
84 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.BufferSizeExceededException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
86 return readBytes( aData
, nMaxBytesToRead
);
89 // ----------------------------------------------------------
90 public synchronized void skipBytes( int nBytesToSkip
)
91 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.BufferSizeExceededException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
93 if ( nBytesToSkip
< 0 )
94 throw new com
.sun
.star
.io
.IOException(); // illegal argument
96 if ( m_nCurSize
- m_nCurPos
> nBytesToSkip
)
97 m_nCurPos
+= nBytesToSkip
;
99 m_nCurPos
= m_nCurSize
;
102 // ----------------------------------------------------------
103 public synchronized int available()
104 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
109 // ----------------------------------------------------------
110 public synchronized void closeInput()
111 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
113 // no need to do anything
121 // ----------------------------------------------------------
122 public synchronized void writeBytes( byte[] aData
)
123 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.BufferSizeExceededException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
125 if ( m_pBytes
!= null && aData
.length
> 0 )
127 if ( aData
.length
> m_nMaxSize
- m_nCurPos
)
128 throw new com
.sun
.star
.io
.IOException();
130 for ( int nInd
= 0; nInd
< aData
.length
; nInd
++ )
131 m_pBytes
[m_nCurPos
+nInd
] = aData
[nInd
];
133 m_nCurPos
+= aData
.length
;
134 if ( m_nCurPos
> m_nCurSize
)
135 m_nCurSize
= m_nCurPos
;
139 // ----------------------------------------------------------
140 public synchronized void flush()
141 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.BufferSizeExceededException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
146 // ----------------------------------------------------------
147 public synchronized void closeOutput()
148 throws com
.sun
.star
.io
.NotConnectedException
, com
.sun
.star
.io
.BufferSizeExceededException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
158 // ----------------------------------------------------------
159 public synchronized void truncate()
160 throws com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
171 // ----------------------------------------------------------
172 public synchronized void seek( long location
)
173 throws com
.sun
.star
.lang
.IllegalArgumentException
, com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
175 if ( location
> (long)m_nCurSize
)
176 throw new com
.sun
.star
.lang
.IllegalArgumentException();
178 m_nCurPos
= (int)location
;
181 // ----------------------------------------------------------
182 public synchronized long getPosition()
183 throws com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
185 return (long)m_nCurPos
;
188 // ----------------------------------------------------------
189 public synchronized long getLength()
190 throws com
.sun
.star
.io
.IOException
, com
.sun
.star
.uno
.RuntimeException
192 return (long)m_nCurSize
;