| 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 | #include "Atomic.h" |
| 29 | #include "FileSystemImpl.h" |
| 30 | #include "Memory.h" |
| 31 | #include "OutputStream.h" |
| 32 | #include "OutputStreamImpl.h" |
| 33 | |
| 34 | using namespace Hdfs::Internal; |
| 35 | |
| 36 | namespace Hdfs { |
| 37 | |
| 38 | OutputStream::OutputStream() { |
| 39 | impl = new Internal::OutputStreamImpl; |
| 40 | } |
| 41 | |
| 42 | OutputStream::~OutputStream() { |
| 43 | delete impl; |
| 44 | } |
| 45 | |
| 46 | void OutputStream::open(FileSystem & fs, const char * path, int flag, |
| 47 | const Permission permission, bool createParent, int replication, |
| 48 | int64_t blockSize) { |
| 49 | if (!fs.impl) { |
| 50 | THROW(HdfsIOException, "FileSystem: not connected." ); |
| 51 | } |
| 52 | |
| 53 | impl->open(fs.impl->filesystem, path, flag, permission, createParent, replication, |
| 54 | blockSize); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * To append data to file. |
| 59 | * @param buf the data used to append. |
| 60 | * @param size the data size. |
| 61 | */ |
| 62 | void OutputStream::append(const char * buf, int64_t size) { |
| 63 | impl->append(buf, size); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Flush all data in buffer and waiting for ack. |
| 68 | * Will block until get all acks. |
| 69 | */ |
| 70 | void OutputStream::flush() { |
| 71 | impl->flush(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * return the current file length. |
| 76 | * @return current file length. |
| 77 | */ |
| 78 | int64_t OutputStream::tell() { |
| 79 | return impl->tell(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * the same as flush right now. |
| 84 | */ |
| 85 | void OutputStream::sync() { |
| 86 | impl->sync(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * close the stream. |
| 91 | */ |
| 92 | void OutputStream::close() { |
| 93 | impl->close(); |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |