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_INPUTSTREAM_H_
29#define _HDFS_LIBHDFS3_CLIENT_INPUTSTREAM_H_
30
31#include "FileSystem.h"
32
33namespace Hdfs {
34namespace Internal {
35class InputStreamInter;
36}
37
38/**
39 * A input stream used read data from hdfs.
40 */
41class InputStream {
42public:
43 InputStream();
44
45 ~InputStream();
46
47 /**
48 * Open a file to read
49 * @param fs hdfs file system.
50 * @param path the file to be read.
51 * @param verifyChecksum verify the checksum.
52 */
53 void open(FileSystem & fs, const char * path, bool verifyChecksum = true);
54
55 /**
56 * To read data from hdfs.
57 * @param buf the buffer used to filled.
58 * @param size buffer size.
59 * @return return the number of bytes filled in the buffer, it may less than size.
60 */
61 int32_t read(char * buf, int32_t size);
62
63 /**
64 * To read data from hdfs, block until get the given size of bytes.
65 * @param buf the buffer used to filled.
66 * @param size the number of bytes to be read.
67 */
68 void readFully(char * buf, int64_t size);
69
70 /**
71 * Get how many bytes can be read without blocking.
72 * @return The number of bytes can be read without blocking.
73 */
74 int64_t available();
75
76 /**
77 * To move the file point to the given position.
78 * @param pos the given position.
79 */
80 void seek(int64_t pos);
81
82 /**
83 * To get the current file point position.
84 * @return the position of current file point.
85 */
86 int64_t tell();
87
88 /**
89 * Close the stream.
90 */
91 void close();
92
93private:
94 Internal::InputStreamInter * impl;
95};
96
97}
98
99#endif /* _HDFS_LIBHDFS3_CLIENT_INPUTSTREAM_H_ */
100