xref: /aosp_15_r20/external/oboe/samples/parselib/src/main/cpp/stream/FileInputStream.h (revision 05767d913155b055644481607e6fa1e35e2fe72c)
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef _IO_STREAM_FILEINPUTSTREAM_H_
17 #define _IO_STREAM_FILEINPUTSTREAM_H_
18 
19 #include "InputStream.h"
20 
21 namespace parselib {
22 
23 /**
24  * A concrete implementation of InputStream for a file data source
25  */
26 class FileInputStream : public InputStream {
27 public:
28     /** constructor. Caller is presumed to have opened the file with (at least) read permission */
FileInputStream(int fh)29     FileInputStream(int fh) : mFH(fh) {}
~FileInputStream()30     virtual ~FileInputStream() {}
31 
32     virtual int32_t read(void *buff, int32_t numBytes);
33 
34     virtual int32_t peek(void *buff, int32_t numBytes);
35 
36     virtual void advance(int32_t numBytes);
37 
38     virtual int32_t getPos();
39 
40     virtual void setPos(int32_t pos);
41 
42 private:
43     /** File handle of the data file to read from */
44     int mFH;
45 };
46 
47 } // namespace parselib
48 
49 #endif // _IO_STREAM_FILEINPUTSTREAM_H_
50