GME  13
BinFileInputStream.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: BinFileInputStream.cpp 670359 2008-06-22 13:43:45Z borisk $
00020  */
00021 
00022 
00023 // ---------------------------------------------------------------------------
00024 //  Includes
00025 // ---------------------------------------------------------------------------
00026 #include <xercesc/util/BinFileInputStream.hpp>
00027 #include <xercesc/util/Janitor.hpp>
00028 #include <xercesc/util/PlatformUtils.hpp>
00029 #include <xercesc/util/XMLExceptMsgs.hpp>
00030 #include <xercesc/util/XMLString.hpp>
00031 
00032 XERCES_CPP_NAMESPACE_BEGIN
00033 
00034 // ---------------------------------------------------------------------------
00035 //  BinFileInputStream: Constructors and Destructor
00036 // ---------------------------------------------------------------------------
00037 BinFileInputStream::BinFileInputStream(const XMLCh* const fileName
00038                                        , MemoryManager* const manager) :
00039 
00040     fSource(XMLPlatformUtils::openFile(fileName, manager))
00041   , fMemoryManager(manager)
00042 {
00043 }
00044 
00045 BinFileInputStream::BinFileInputStream(const char* const fileName,
00046                                        MemoryManager* const manager) :
00047 
00048     fSource(XMLPlatformUtils::openFile(fileName, manager))
00049   , fMemoryManager(manager)
00050 {
00051 }
00052 
00053 BinFileInputStream::BinFileInputStream(const FileHandle toAdopt
00054                                        , MemoryManager* const manager) :
00055 
00056     fSource(toAdopt)
00057   , fMemoryManager(manager)
00058 {
00059 }
00060 
00061 BinFileInputStream::~BinFileInputStream()
00062 {
00063     if (getIsOpen())
00064         XMLPlatformUtils::closeFile(fSource, fMemoryManager);
00065 }
00066 
00067 
00068 // ---------------------------------------------------------------------------
00069 //  BinFileInputStream: Getter methods
00070 // ---------------------------------------------------------------------------
00071 XMLFilePos BinFileInputStream::getSize() const
00072 {
00073     return XMLPlatformUtils::fileSize(fSource, fMemoryManager);
00074 }
00075 
00076 
00077 // ---------------------------------------------------------------------------
00078 //  BinFileInputStream: Stream management methods
00079 // ---------------------------------------------------------------------------
00080 void BinFileInputStream::reset()
00081 {
00082     XMLPlatformUtils::resetFile(fSource, fMemoryManager);
00083 }
00084 
00085 
00086 // ---------------------------------------------------------------------------
00087 //  BinFileInputStream: Implementation of the input stream interface
00088 // ---------------------------------------------------------------------------
00089 XMLFilePos BinFileInputStream::curPos() const
00090 {
00091     return XMLPlatformUtils::curFilePos(fSource, fMemoryManager);
00092 }
00093 
00094 XMLSize_t
00095 BinFileInputStream::readBytes(          XMLByte* const  toFill
00096                                 , const XMLSize_t       maxToRead)
00097 {
00098     //
00099     //  Read up to the maximum bytes requested. We return the number
00100     //  actually read.
00101     //
00102     return XMLPlatformUtils::readFileBuffer(fSource, maxToRead, toFill, fMemoryManager);
00103 }
00104 
00105 const XMLCh* BinFileInputStream::getContentType() const
00106 {
00107     return 0;
00108 }
00109 
00110 XERCES_CPP_NAMESPACE_END