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_OUTPUTSTREAMINTER_H_
29#define _HDFS_LIBHDFS3_CLIENT_OUTPUTSTREAMINTER_H_
30
31#include "ExceptionInternal.h"
32#include "FileSystemInter.h"
33#include "Memory.h"
34#include "Permission.h"
35
36namespace Hdfs {
37namespace Internal {
38
39/**
40 * A output stream used to write data to hdfs.
41 */
42class OutputStreamInter {
43public:
44 virtual ~OutputStreamInter() {
45 }
46
47 /**
48 * To create or append a file.
49 * @param fs hdfs file system.
50 * @param path the file path.
51 * @param flag creation flag, can be Create, Append or Create|Overwrite.
52 * @param permission create a new file with given permission.
53 * @param createParent if the parent does not exist, create it.
54 * @param replication create a file with given number of replication.
55 * @param blockSize create a file with given block size.
56 */
57 virtual void open(shared_ptr<FileSystemInter> fs, const char * path, int flag,
58 const Permission & permission, bool createParent, int replication,
59 int64_t blockSize) = 0;
60
61 /**
62 * To append data to file.
63 * @param buf the data used to append.
64 * @param size the data size.
65 */
66 virtual void append(const char * buf, int64_t size) = 0;
67
68 /**
69 * Flush all data in buffer and waiting for ack.
70 * Will block until get all acks.
71 */
72 virtual void flush() = 0;
73
74 /**
75 * return the current file length.
76 * @return current file length.
77 */
78 virtual int64_t tell() = 0;
79
80 /**
81 * @ref OutputStream::sync
82 */
83 virtual void sync() = 0;
84
85 /**
86 * close the stream.
87 */
88 virtual void close() = 0;
89
90 virtual std::string toString() = 0;
91
92 virtual void setError(const exception_ptr & error) = 0;
93};
94
95}
96}
97
98#endif /* _HDFS_LIBHDFS3_CLIENT_OUTPUTSTREAMINTER_H_ */
99