1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * 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, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: BinFileInputStream.cpp 670359 2008-06-22 13:43:45Z borisk $ |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | // --------------------------------------------------------------------------- |
---|
24 | // Includes |
---|
25 | // --------------------------------------------------------------------------- |
---|
26 | #include <xercesc/util/BinFileInputStream.hpp> |
---|
27 | #include <xercesc/util/Janitor.hpp> |
---|
28 | #include <icxercesc/util/PlatformUtils.hpp> |
---|
29 | #include <xercesc/util/XMLExceptMsgs.hpp> |
---|
30 | #include <icxercesc/util/XMLString.hpp> |
---|
31 | |
---|
32 | XERCES_CPP_NAMESPACE_BEGIN |
---|
33 | |
---|
34 | // --------------------------------------------------------------------------- |
---|
35 | // BinFileInputStream: Constructors and Destructor |
---|
36 | // --------------------------------------------------------------------------- |
---|
37 | BinFileInputStream::BinFileInputStream(const XMLCh* const fileName |
---|
38 | , MemoryManager* const manager) : |
---|
39 | |
---|
40 | fSource(XMLPlatformUtils::openFile(fileName, manager)) |
---|
41 | , fMemoryManager(manager) |
---|
42 | { |
---|
43 | } |
---|
44 | |
---|
45 | BinFileInputStream::BinFileInputStream(const char* const fileName, |
---|
46 | MemoryManager* const manager) : |
---|
47 | |
---|
48 | fSource(XMLPlatformUtils::openFile(fileName, manager)) |
---|
49 | , fMemoryManager(manager) |
---|
50 | { |
---|
51 | } |
---|
52 | |
---|
53 | BinFileInputStream::BinFileInputStream(const FileHandle toAdopt |
---|
54 | , MemoryManager* const manager) : |
---|
55 | |
---|
56 | fSource(toAdopt) |
---|
57 | , fMemoryManager(manager) |
---|
58 | { |
---|
59 | } |
---|
60 | |
---|
61 | BinFileInputStream::~BinFileInputStream() |
---|
62 | { |
---|
63 | if (getIsOpen()) |
---|
64 | XMLPlatformUtils::closeFile(fSource, fMemoryManager); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | // --------------------------------------------------------------------------- |
---|
69 | // BinFileInputStream: Getter methods |
---|
70 | // --------------------------------------------------------------------------- |
---|
71 | XMLFilePos BinFileInputStream::getSize() const |
---|
72 | { |
---|
73 | return XMLPlatformUtils::fileSize(fSource, fMemoryManager); |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | // --------------------------------------------------------------------------- |
---|
78 | // BinFileInputStream: Stream management methods |
---|
79 | // --------------------------------------------------------------------------- |
---|
80 | void BinFileInputStream::reset() |
---|
81 | { |
---|
82 | XMLPlatformUtils::resetFile(fSource, fMemoryManager); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | // --------------------------------------------------------------------------- |
---|
87 | // BinFileInputStream: Implementation of the input stream interface |
---|
88 | // --------------------------------------------------------------------------- |
---|
89 | XMLFilePos BinFileInputStream::curPos() const |
---|
90 | { |
---|
91 | return XMLPlatformUtils::curFilePos(fSource, fMemoryManager); |
---|
92 | } |
---|
93 | |
---|
94 | XMLSize_t |
---|
95 | BinFileInputStream::readBytes( XMLByte* const toFill |
---|
96 | , const XMLSize_t maxToRead) |
---|
97 | { |
---|
98 | // |
---|
99 | // Read up to the maximum bytes requested. We return the number |
---|
100 | // actually read. |
---|
101 | // |
---|
102 | return XMLPlatformUtils::readFileBuffer(fSource, maxToRead, toFill, fMemoryManager); |
---|
103 | } |
---|
104 | |
---|
105 | const XMLCh* BinFileInputStream::getContentType() const |
---|
106 | { |
---|
107 | return 0; |
---|
108 | } |
---|
109 | |
---|
110 | XERCES_CPP_NAMESPACE_END |
---|