#include <ACEXML/common/FileCharStream.h>
Inheritance diagram for ACEXML_FileCharStream:
Public Member Functions | |
ACEXML_FileCharStream (void) | |
Default constructor. | |
virtual | ~ACEXML_FileCharStream (void) |
Destructor. | |
int | open (const ACEXML_Char *name) |
Open a file. | |
virtual int | available (void) |
virtual int | close (void) |
virtual int | get (ACEXML_Char &ch) |
virtual int | read (ACEXML_Char *str, size_t len) |
virtual int | determine_encoding (void) |
virtual int | peek (void) |
virtual void | rewind (void) |
virtual const ACEXML_Char * | getEncoding (void) |
virtual const ACEXML_Char * | getSystemId (void) |
Private Member Functions | |
int | getchar_i (char &ch) |
Private Attributes | |
ACEXML_Char * | filename_ |
ACEXML_Char * | encoding_ |
ACE_OFF_T | size_ |
FILE * | infile_ |
ACEXML_Char | peek_ |
Definition at line 31 of file FileCharStream.h.
|
Default constructor.
Definition at line 14 of file FileCharStream.cpp.
|
|
Destructor.
Definition at line 19 of file FileCharStream.cpp. References close().
00020 { 00021 this->close(); 00022 } |
|
Returns the available ACEXML_Char in the buffer. -1 if the object is not initialized properly. Implements ACEXML_CharStream. Definition at line 102 of file FileCharStream.cpp. References ACE_OS::ftell(), and infile_.
00103 { 00104 if (this->infile_ == 0) 00105 return -1; 00106 00107 long curr; 00108 if ((curr = ACE_OS::ftell (this->infile_)) < 0) 00109 return -1; 00110 return static_cast<int> (this->size_ - curr); 00111 } |
|
Close this stream and release all resources used by it. Implements ACEXML_CharStream. Definition at line 114 of file FileCharStream.cpp. References encoding_, ACE_OS::fclose(), infile_, and peek_. Referenced by ~ACEXML_FileCharStream().
00115 { 00116 if (this->infile_ != 0) 00117 { 00118 ACE_OS::fclose (this->infile_); 00119 this->infile_ = 0; 00120 } 00121 delete[] this->filename_; 00122 this->filename_ = 0; 00123 delete[] this->encoding_; 00124 this->encoding_ = 0; 00125 this->size_ = 0; 00126 this->peek_ = 0; 00127 return 0; 00128 } |
|
Determine the encoding of the file. Definition at line 47 of file FileCharStream.cpp. References ACEXML_Char, encoding_, ACEXML_Encoding::get_encoding(), getchar_i(), infile_, ACE_OS::rewind(), ACE::strnew(), and ACE_OS::ungetc(). Referenced by open(), and rewind().
00048 { 00049 if (this->infile_ == 0) 00050 return -1; 00051 00052 char input[4]; 00053 int retval = 0; 00054 int i = 0; 00055 for (; i < 4 && retval != -1; ++i) 00056 retval = this->getchar_i(input[i]); 00057 if (i < 4) 00058 return -1; 00059 00060 // Rewind the stream 00061 ACE_OS::rewind (this->infile_); 00062 00063 const ACEXML_Char* temp = ACEXML_Encoding::get_encoding (input); 00064 if (!temp) 00065 return -1; 00066 else 00067 { 00068 if (this->encoding_) 00069 delete [] this->encoding_; 00070 this->encoding_ = ACE::strnew (temp); 00071 // ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("File's encoding is %s\n"), 00072 // this->encoding_)); 00073 } 00074 // Move over the byte-order-mark if present. 00075 char ch; 00076 for (int j = 0; j < 3; ++j) 00077 { 00078 if (this->getchar_i (ch) < 0) 00079 return -1; 00080 if (ch == '\xFF' || ch == '\xFE' || ch == '\xEF' || ch == '\xBB' || 00081 ch == '\xBF') 00082 continue; 00083 else 00084 { 00085 ACE_OS::ungetc (ch, this->infile_); 00086 break; 00087 } 00088 } 00089 return 0; 00090 } |
|
Read the next ACEXML_Char. Return -1 if we are not able to return an ACEXML_Char, 0 if succees. Implements ACEXML_CharStream. Definition at line 149 of file FileCharStream.cpp. References ACEXML_Char, ACE_OS::fgetc(), and infile_.
00150 { 00151 if (this->infile_ == 0) 00152 return -1; 00153 #if defined (ACE_USES_WCHAR) 00154 return this->get_i (ch); 00155 #else 00156 ch = (ACEXML_Char) ACE_OS::fgetc (this->infile_); 00157 return (feof(this->infile_) ? -1 : 0); 00158 #endif /* ACE_USES_WCHAR */ 00159 } |
|
Read the next character as a normal character. Return -1 if EOF is reached, else return 0. Definition at line 132 of file FileCharStream.cpp. References ACE_OS::fgetc(). Referenced by determine_encoding().
00133 { 00134 ch = static_cast<char> (ACE_OS::fgetc (this->infile_)); 00135 return (feof(this->infile_) ? -1 : 0); 00136 } |
|
Implements ACEXML_CharStream. Definition at line 247 of file FileCharStream.cpp. References encoding_.
00248 { 00249 return this->encoding_; 00250 } |
|
Implements ACEXML_CharStream. Definition at line 253 of file FileCharStream.cpp.
00254 { 00255 return this->filename_; 00256 } |
|
Open a file.
Definition at line 25 of file FileCharStream.cpp. References ACE_stat, ACE_TEXT, ACEXML_Char, determine_encoding(), encoding_, ACE_OS::fopen(), infile_, ACE_OS::stat(), and ACE::strnew(). Referenced by ACEXML_StreamFactory::create_stream().
00026 { 00027 delete[] this->filename_; 00028 this->filename_ = 0; 00029 00030 delete[] this->encoding_; 00031 this->encoding_ = 0; 00032 00033 this->infile_ = ACE_OS::fopen (name, ACE_TEXT ("r")); 00034 if (this->infile_ == 0) 00035 return -1; 00036 00037 ACE_stat statbuf; 00038 if (ACE_OS::stat (name, &statbuf) < 0) 00039 return -1; 00040 00041 this->size_ = ACE_Utils::truncate_cast<ACE_OFF_T> (statbuf.st_size); 00042 this->filename_ = ACE::strnew (name); 00043 return this->determine_encoding(); 00044 } |
|
Peek the next ACEXML_Char in the CharStream. Return the character if success, -1 if EOF is reached. Implements ACEXML_CharStream. Definition at line 162 of file FileCharStream.cpp. References ACEXML_Char, ACE_OS::fgetc(), infile_, and ACE_OS::ungetc().
00163 { 00164 if (this->infile_ == 0) 00165 return -1; 00166 #if defined (ACE_USES_WCHAR) 00167 return this->peek_i(); 00168 #else 00169 00170 ACEXML_Char ch = static_cast<ACEXML_Char> (ACE_OS::fgetc (this->infile_)); 00171 ACE_OS::ungetc (ch, this->infile_); 00172 return ch; 00173 #endif /* ACE_USES_WCHAR */ 00174 } |
|
Read the next batch of ACEXML_Char strings Implements ACEXML_CharStream. Definition at line 139 of file FileCharStream.cpp. References ACEXML_Char, ACE_OS::fread(), and infile_.
00141 { 00142 if (this->infile_ == 0) 00143 return -1; 00144 00145 return static_cast<int> (ACE_OS::fread (str, sizeof (ACEXML_Char), len, this->infile_)); 00146 } |
|
Resets the file pointer to the beginning of the stream. Implements ACEXML_CharStream. Definition at line 93 of file FileCharStream.cpp. References determine_encoding(), infile_, and ACE_OS::rewind().
00094 { 00095 if (this->infile_ == 0) 00096 return; 00097 ACE_OS::rewind (this->infile_); 00098 this->determine_encoding(); 00099 } |
|
Definition at line 117 of file FileCharStream.h. Referenced by close(), determine_encoding(), getEncoding(), and open(). |
|
Definition at line 116 of file FileCharStream.h. |
|
Definition at line 119 of file FileCharStream.h. Referenced by available(), close(), determine_encoding(), get(), open(), peek(), read(), and rewind(). |
|
Definition at line 124 of file FileCharStream.h. Referenced by close(). |
|
Definition at line 118 of file FileCharStream.h. |