1 /* 2 * Copyright 2011 Google Inc. All Rights Reserved. 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 17 #ifndef SFNTLY_CPP_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ 18 #define SFNTLY_CPP_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ 19 20 #include <stdio.h> 21 22 #include "sfntly/port/input_stream.h" 23 24 namespace sfntly { 25 26 class FileInputStream : public PushbackInputStream { 27 public: 28 FileInputStream(); 29 virtual ~FileInputStream(); 30 31 // InputStream methods 32 virtual int32_t Length(); 33 virtual int32_t Available(); 34 virtual void Close(); 35 virtual void Mark(int32_t readlimit); 36 virtual bool MarkSupported(); 37 virtual int32_t Read(); 38 virtual int32_t Read(std::vector<uint8_t>* b); 39 virtual int32_t Read(std::vector<uint8_t>* b, int32_t offset, int32_t length); 40 virtual void Reset(); 41 virtual int64_t Skip(int64_t n); 42 43 // PushbackInputStream methods 44 virtual void Unread(std::vector<uint8_t>* b); 45 virtual void Unread(std::vector<uint8_t>* b, int32_t offset, int32_t length); 46 47 // Own methods 48 virtual bool Open(const char* file_path); 49 50 private: 51 FILE* file_; 52 size_t position_; 53 size_t length_; 54 }; 55 56 } // namespace sfntly 57 58 #endif // SFNTLY_CPP_SRC_SFNTLY_PORT_FILE_INPUT_STREAM_H_ 59