1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#include "arrow/io/interfaces.h"
19
20#include <cstdint>
21#include <memory>
22#include <mutex>
23
24#include "arrow/status.h"
25#include "arrow/util/string_view.h"
26
27namespace arrow {
28namespace io {
29
30FileInterface::~FileInterface() = default;
31
32Status InputStream::Advance(int64_t nbytes) {
33 std::shared_ptr<Buffer> temp;
34 return Read(nbytes, &temp);
35}
36
37util::string_view InputStream::Peek(int64_t ARROW_ARG_UNUSED(nbytes)) const {
38 return util::string_view(nullptr, 0);
39}
40
41bool InputStream::supports_zero_copy() const { return false; }
42
43struct RandomAccessFile::RandomAccessFileImpl {
44 std::mutex lock_;
45};
46
47RandomAccessFile::~RandomAccessFile() = default;
48
49RandomAccessFile::RandomAccessFile()
50 : interface_impl_(new RandomAccessFile::RandomAccessFileImpl()) {}
51
52Status RandomAccessFile::ReadAt(int64_t position, int64_t nbytes, int64_t* bytes_read,
53 void* out) {
54 std::lock_guard<std::mutex> lock(interface_impl_->lock_);
55 RETURN_NOT_OK(Seek(position));
56 return Read(nbytes, bytes_read, out);
57}
58
59Status RandomAccessFile::ReadAt(int64_t position, int64_t nbytes,
60 std::shared_ptr<Buffer>* out) {
61 std::lock_guard<std::mutex> lock(interface_impl_->lock_);
62 RETURN_NOT_OK(Seek(position));
63 return Read(nbytes, out);
64}
65
66Status Writable::Write(const std::string& data) {
67 return Write(data.c_str(), static_cast<int64_t>(data.size()));
68}
69
70Status Writable::Flush() { return Status::OK(); }
71
72} // namespace io
73} // namespace arrow
74