Debian Codegraph @

scripting/java/com/sun/star/script/framework/io/XInputStreamWrapper.java

raw
1 /*
2 * This file is part of the LibreOffice project.
3 *
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/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
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 .
17 */
18 package com.sun.star.script.framework.io;
19
20 import com.sun.star.io.XInputStream;
21
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 public class XInputStreamWrapper extends InputStream {
26
27 private final XInputStream m_xInputStream;
28
29 public XInputStreamWrapper(XInputStream xInputStream) {
30 m_xInputStream = xInputStream;
31 }
32
33 @Override
34 public int read() throws java.io.IOException {
35 byte[][] byteRet = new byte[1][0];
36 long numRead;
37
38 try {
39 numRead = m_xInputStream.readBytes(byteRet, 1);
40 } catch (com.sun.star.io.IOException ex1) {
41 IOException ex2 = new IOException();
42 ex2.initCause(ex1);
43 throw ex2;
44 }
45
46 if (numRead != 1) {
47 return -1;
48 }
49
50 return byteRet[0][0];
51 }
52
53 @Override
54 public int read(byte[] b) throws java.io.IOException {
55 byte[][] byteRet = new byte[1][];
56 byteRet[0] = b;
57
58 try {
59 return m_xInputStream.readBytes(byteRet, b.length);
60 } catch (com.sun.star.io.IOException ex1) {
61 IOException ex2 = new IOException();
62 ex2.initCause(ex1);
63 throw ex2;
64 }
65 }
66
67 @Override
68 public long skip(long n) throws java.io.IOException {
69 try {
70 m_xInputStream.skipBytes((int)n);
71 return n;
72 } catch (com.sun.star.io.IOException ex1) {
73 IOException ex2 = new IOException();
74 ex2.initCause(ex1);
75 throw ex2;
76 }
77 }
78
79 @Override
80 public int available() throws java.io.IOException {
81 try {
82 return m_xInputStream.available();
83 } catch (com.sun.star.io.IOException ex1) {
84 IOException ex2 = new IOException();
85 ex2.initCause(ex1);
86 throw ex2;
87 }
88 }
89
90 @Override
91 public void close() throws java.io.IOException {
92 try {
93 m_xInputStream.closeInput();
94 } catch (com.sun.star.io.IOException ex1) {
95 IOException ex2 = new IOException();
96 ex2.initCause(ex1);
97 throw ex2;
98 }
99 }
100 }