source: proiecte/HadoopJUnit/hadoop-0.20.1/src/c++/librecordio/filestream.cc @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "filestream.hh"
20
21using namespace hadoop;
22
23hadoop::FileInStream::FileInStream()
24{
25  mFile = NULL;
26}
27
28bool hadoop::FileInStream::open(const std::string& name)
29{
30  mFile = fopen(name.c_str(), "rb");
31  return (mFile != NULL);
32}
33
34ssize_t hadoop::FileInStream::read(void *buf, size_t len)
35{
36  return fread(buf, 1, len, mFile);
37}
38
39bool hadoop::FileInStream::skip(size_t nbytes)
40{
41  return (0==fseek(mFile, nbytes, SEEK_CUR));
42}
43
44bool hadoop::FileInStream::close()
45{
46  int ret = fclose(mFile);
47  mFile = NULL;
48  return (ret==0);
49}
50
51hadoop::FileInStream::~FileInStream()
52{
53  if (mFile != NULL) {
54    close();
55  }
56}
57
58hadoop::FileOutStream::FileOutStream()
59{
60  mFile = NULL;
61}
62
63bool hadoop::FileOutStream::open(const std::string& name, bool overwrite)
64{
65  if (!overwrite) {
66    mFile = fopen(name.c_str(), "rb");
67    if (mFile != NULL) {
68      fclose(mFile);
69      return false;
70    }
71  }
72  mFile = fopen(name.c_str(), "wb");
73  return (mFile != NULL);
74}
75
76ssize_t hadoop::FileOutStream::write(const void* buf, size_t len)
77{
78  return fwrite(buf, 1, len, mFile);
79}
80
81bool hadoop::FileOutStream::advance(size_t nbytes)
82{
83  return (0==fseek(mFile, nbytes, SEEK_CUR));
84}
85
86bool hadoop::FileOutStream::close()
87{
88  int ret = fclose(mFile);
89  mFile = NULL;
90  return (ret == 0);
91}
92
93hadoop::FileOutStream::~FileOutStream()
94{
95  if (mFile != NULL) {
96    close();
97  }
98}
Note: See TracBrowser for help on using the repository browser.