private InputStream getFileStreamFromUCB(String path)
throws IOException
{
InputStream result = null;
XInputStream xInputStream = null;
try {
LogUtils.DEBUG("Trying to read from " + path );
xInputStream = m_xSimpleFileAccess.openFileRead(path);
LogUtils.DEBUG("sfa appeared to read file " );
byte[][] inputBytes = new byte[1][];
int ln = 0;
int sz = m_xSimpleFileAccess.getSize(path);
// TODO don't depend on result of available() or size()
// just read stream 'till complete
if ( sz == 0 )
{
if ( xInputStream.available() > 0 )
{
sz = xInputStream.available();
}
}
LogUtils.DEBUG("size of file " + path + " is " + sz );
LogUtils.DEBUG("available = " + xInputStream.available() );
inputBytes[0] = new byte[sz];
ln = xInputStream.readBytes(inputBytes, sz);
if (ln != sz) {
throw new IOException(
"Failed to read " + sz + " bytes from XInputStream");
}
result = new ByteArrayInputStream(inputBytes[0]);
}
catch (com.sun.star.io.IOException ioe) {
LogUtils.DEBUG("caught exception " + ioe );
throw new IOException(ioe.getMessage());
}
catch (com.sun.star.uno.Exception e) {
LogUtils.DEBUG("caught exception " + e );
throw new IOException(e.getMessage());
}
finally
{
if (xInputStream != null) {
try {
xInputStream.closeInput();
}
catch (Exception e2) {
LogUtils.DEBUG(
"Error closing XInputStream:" + e2.getMessage());
}