1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/io/stdio.h"
#include <iostream>
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/buffer.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/result.h"
namespace arrow20 {
namespace io {
//
// StdoutStream implementation
//
StdoutStream::StdoutStream() : pos_(0) { set_mode(FileMode::WRITE); }
Status StdoutStream::Close() { return Status::OK(); }
bool StdoutStream::closed() const { return false; }
Result<int64_t> StdoutStream::Tell() const { return pos_; }
Status StdoutStream::Write(const void* data, int64_t nbytes) {
pos_ += nbytes;
std::cout.write(reinterpret_cast<const char*>(data), nbytes);
return Status::OK();
}
//
// StderrStream implementation
//
StderrStream::StderrStream() : pos_(0) { set_mode(FileMode::WRITE); }
Status StderrStream::Close() { return Status::OK(); }
bool StderrStream::closed() const { return false; }
Result<int64_t> StderrStream::Tell() const { return pos_; }
Status StderrStream::Write(const void* data, int64_t nbytes) {
pos_ += nbytes;
std::cerr.write(reinterpret_cast<const char*>(data), nbytes);
return Status::OK();
}
//
// StdinStream implementation
//
StdinStream::StdinStream() : pos_(0) { set_mode(FileMode::READ); }
Status StdinStream::Close() { return Status::OK(); }
bool StdinStream::closed() const { return false; }
Result<int64_t> StdinStream::Tell() const { return pos_; }
Result<int64_t> StdinStream::Read(int64_t nbytes, void* out) {
std::cin.read(reinterpret_cast<char*>(out), nbytes);
nbytes = std::cin.gcount();
pos_ += nbytes;
return nbytes;
}
Result<std::shared_ptr<Buffer>> StdinStream::Read(int64_t nbytes) {
ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateResizableBuffer(nbytes));
ARROW_ASSIGN_OR_RAISE(int64_t bytes_read, Read(nbytes, buffer->mutable_data()));
ARROW_RETURN_NOT_OK(buffer->Resize(bytes_read, false));
buffer->ZeroPadding();
// R build with openSUSE155 requires an explicit shared_ptr construction
return std::shared_ptr<Buffer>(std::move(buffer));
}
} // namespace io
} // namespace arrow20
|