tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / package / qa / storages / BorderedStream.java
blobce7ebe55ff4b50c4d725d05905b7e7274be0c29b
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex.storages;
21 import com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.lang.XSingleServiceFactory;
25 import com.sun.star.bridge.XUnoUrlResolver;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
29 import com.sun.star.io.XStream;
30 import com.sun.star.io.XInputStream;
31 import com.sun.star.io.XOutputStream;
32 import com.sun.star.io.XTruncate;
33 import com.sun.star.io.XSeekable;
36 public class BorderedStream
37 implements XStream, XInputStream, XOutputStream, XTruncate, XSeekable
39 int m_nMaxSize;
40 int m_nCurSize;
41 int m_nCurPos;
42 byte m_pBytes[];
44 public BorderedStream( int nMaxSize )
46 m_nMaxSize = nMaxSize;
47 m_nCurSize = 0;
48 m_nCurPos = 0;
49 m_pBytes = new byte[m_nMaxSize];
53 // XStream
57 public synchronized XInputStream getInputStream()
58 throws com.sun.star.uno.RuntimeException
60 return (XInputStream)UnoRuntime.queryInterface( XInputStream.class, this );
64 public synchronized XOutputStream getOutputStream()
65 throws com.sun.star.uno.RuntimeException
67 return (XOutputStream)UnoRuntime.queryInterface( XOutputStream.class, this );
71 // XInputStream
75 public synchronized int readBytes( byte[][] aData, int nBytesToRead )
76 throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
78 int nRead = 0;
79 if ( m_pBytes != null && nBytesToRead > 0 )
81 int nAvailable = m_nCurSize - m_nCurPos;
82 if ( nBytesToRead > nAvailable )
83 nBytesToRead = nAvailable;
85 aData[0] = new byte[nBytesToRead];
86 for ( int nInd = 0; nInd < nBytesToRead; nInd++ )
87 aData[0][nInd] = m_pBytes[m_nCurPos+nInd];
89 nRead = nBytesToRead;
90 m_nCurPos += nRead;
92 else
94 aData[0] = new byte[0];
97 return nRead;
101 public synchronized int readSomeBytes( byte[][] aData, int nMaxBytesToRead )
102 throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
104 return readBytes( aData, nMaxBytesToRead );
108 public synchronized void skipBytes( int nBytesToSkip )
109 throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
111 if ( nBytesToSkip < 0 )
112 throw new com.sun.star.io.IOException(); // illegal argument
114 if ( m_nCurSize - m_nCurPos > nBytesToSkip )
115 m_nCurPos += nBytesToSkip;
116 else
117 m_nCurPos = m_nCurSize;
121 public synchronized int available()
122 throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
124 return 0;
128 public synchronized void closeInput()
129 throws com.sun.star.io.NotConnectedException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
131 // no need to do anything
136 // XOutputStream
140 public synchronized void writeBytes( byte[] aData )
141 throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
143 if ( m_pBytes != null && aData.length > 0 )
145 if ( aData.length > m_nMaxSize - m_nCurPos )
146 throw new com.sun.star.io.IOException();
148 for ( int nInd = 0; nInd < aData.length; nInd++ )
149 m_pBytes[m_nCurPos+nInd] = aData[nInd];
151 m_nCurPos += aData.length;
152 if ( m_nCurPos > m_nCurSize )
153 m_nCurSize = m_nCurPos;
158 public synchronized void flush()
159 throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
161 // nothing to do
165 public synchronized void closeOutput()
166 throws com.sun.star.io.NotConnectedException, com.sun.star.io.BufferSizeExceededException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
168 // nothing to do
173 // XTruncate
177 public synchronized void truncate()
178 throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
180 m_nCurSize = 0;
181 m_nCurPos = 0;
186 // XSeekable
190 public synchronized void seek( long location )
191 throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
193 if ( location > (long)m_nCurSize )
194 throw new com.sun.star.lang.IllegalArgumentException();
196 m_nCurPos = (int)location;
200 public synchronized long getPosition()
201 throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
203 return (long)m_nCurPos;
207 public synchronized long getLength()
208 throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException
210 return (long)m_nCurSize;