1/********************************************************************
2 * Copyright (c) 2013 - 2014, Pivotal Inc.
3 * All rights reserved.
4 *
5 * Author: Zhanwei Wang
6 ********************************************************************/
7/********************************************************************
8 * 2014 -
9 * open source under Apache License Version 2.0
10 ********************************************************************/
11/**
12 * Licensed to the Apache Software Foundation (ASF) under one
13 * or more contributor license agreements. See the NOTICE file
14 * distributed with this work for additional information
15 * regarding copyright ownership. The ASF licenses this file
16 * to you under the Apache License, Version 2.0 (the
17 * "License"); you may not use this file except in compliance
18 * with the License. You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS,
24 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
27 */
28#ifndef _HDFS_LIBHDFS3_CLIENT_INPUTSTREAMINTER_H_
29#define _HDFS_LIBHDFS3_CLIENT_INPUTSTREAMINTER_H_
30
31#include <Memory.h>
32
33#include <string>
34
35namespace Hdfs {
36namespace Internal {
37
38class FileSystemInter;
39
40/**
41 * A input stream used read data from hdfs.
42 */
43class InputStreamInter {
44public:
45
46 virtual ~InputStreamInter() {
47 }
48
49 /**
50 * Open a file to read
51 * @param fs hdfs file system.
52 * @param path the file to be read.
53 * @param verifyChecksum verify the checksum.
54 */
55 virtual void open(shared_ptr<FileSystemInter> fs, const char * path,
56 bool verifyChecksum) = 0;
57
58 /**
59 * To read data from hdfs.
60 * @param buf the buffer used to filled.
61 * @param size buffer size.
62 * @return return the number of bytes filled in the buffer, it may less than size.
63 */
64 virtual int32_t read(char * buf, int32_t size) = 0;
65
66 /**
67 * To read data from hdfs, block until get the given size of bytes.
68 * @param buf the buffer used to filled.
69 * @param size the number of bytes to be read.
70 */
71 virtual void readFully(char * buf, int64_t size) = 0;
72
73 /**
74 * Get how many bytes can be read without blocking.
75 * @return The number of bytes can be read without blocking.
76 */
77 virtual int64_t available() = 0;
78
79 /**
80 * To move the file point to the given position.
81 * @param pos the given position.
82 */
83 virtual void seek(int64_t pos) = 0;
84
85 /**
86 * To get the current file point position.
87 * @return the position of current file point.
88 */
89 virtual int64_t tell() = 0;
90
91 /**
92 * Close the stream.
93 */
94 virtual void close() = 0;
95
96 /**
97 * Output a readable string of this input stream.
98 */
99 virtual std::string toString() = 0;
100};
101
102}
103}
104#endif /* _HDFS_LIBHDFS3_CLIENT_INPUTSTREAMINTER_H_ */
105