]> git.basschouten.com Git - openhab-addons.git/blob
144ba4334de5758c69cc1f161b09f4890102b18d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.voice.mimic.internal;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.core.audio.AudioException;
22 import org.openhab.core.audio.AudioFormat;
23 import org.openhab.core.audio.FixedLengthAudioStream;
24
25 /**
26  * An AudioStream with an {@link InputStream} inside
27  *
28  * @author Gwendal Roulleau - Initial contribution
29  */
30 @NonNullByDefault
31 public class InputStreamAudioStream extends FixedLengthAudioStream {
32
33     public InputStream innerInputStream;
34     public AudioFormat audioFormat;
35     public long length;
36
37     public InputStreamAudioStream(InputStream innerInputStream, AudioFormat audioFormat, long length) {
38         super();
39         this.innerInputStream = innerInputStream;
40         this.audioFormat = audioFormat;
41         this.length = length;
42     }
43
44     @Override
45     public AudioFormat getFormat() {
46         return audioFormat;
47     }
48
49     @Override
50     public int read() throws IOException {
51         return innerInputStream.read();
52     }
53
54     @Override
55     public int read(byte @Nullable [] b) throws IOException {
56         return innerInputStream.read(b);
57     }
58
59     @Override
60     public int read(byte @Nullable [] b, int off, int len) throws IOException {
61         return innerInputStream.read(b, off, len);
62     }
63
64     @Override
65     public byte[] readAllBytes() throws IOException {
66         return innerInputStream.readAllBytes();
67     }
68
69     @Override
70     public byte[] readNBytes(int len) throws IOException {
71         return innerInputStream.readNBytes(len);
72     }
73
74     @Override
75     public int readNBytes(byte @Nullable [] b, int off, int len) throws IOException {
76         return innerInputStream.readNBytes(b, off, len);
77     }
78
79     @Override
80     public long skip(long n) throws IOException {
81         return innerInputStream.skip(n);
82     }
83
84     @Override
85     public int available() throws IOException {
86         return innerInputStream.available();
87     }
88
89     @Override
90     public void close() throws IOException {
91         innerInputStream.close();
92     }
93
94     @Override
95     public synchronized void mark(int readlimit) {
96         innerInputStream.mark(readlimit);
97     }
98
99     @Override
100     public synchronized void reset() throws IOException {
101         innerInputStream.reset();
102     }
103
104     @Override
105     public boolean markSupported() {
106         return innerInputStream.markSupported();
107     }
108
109     @Override
110     public long transferTo(@Nullable OutputStream out) throws IOException {
111         return innerInputStream.transferTo(out);
112     }
113
114     @Override
115     public long length() {
116         return length;
117     }
118
119     @Override
120     public InputStream getClonedStream() throws AudioException {
121         throw new AudioException("Operation not supported");
122     }
123 }