< prev index next >

src/hotspot/share/utilities/ostream.hpp

Print this page
rev 58767 : 8242485: Null _file checking in fileStream::flush()


 213   // Return number of characters written into buffer, excluding terminating zero and
 214   // subject to truncation in static buffer mode.
 215   size_t      size() const { return buffer_pos; }
 216   const char* base() const { return buffer; }
 217   void  reset();
 218   char* as_string() const;
 219 };
 220 
 221 class fileStream : public outputStream {
 222  protected:
 223   FILE* _file;
 224   bool  _need_close;
 225  public:
 226   fileStream() { _file = NULL; _need_close = false; }
 227   fileStream(const char* file_name);
 228   fileStream(const char* file_name, const char* opentype);
 229   fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
 230   ~fileStream();
 231   bool is_open() const { return _file != NULL; }
 232   virtual void write(const char* c, size_t len);
 233   size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }



 234   char* readln(char *data, int count);
 235   int eof() { return feof(_file); }
 236   long fileSize();
 237   void rewind() { ::rewind(_file); }
 238   void flush();
 239 };
 240 
 241 CDS_ONLY(extern fileStream*   classlist_file;)
 242 
 243 // unlike fileStream, fdStream does unbuffered I/O by calling
 244 // open() and write() directly. It is async-safe, but output
 245 // from multiple thread may be mixed together. Used by fatal
 246 // error handler.
 247 class fdStream : public outputStream {
 248  protected:
 249   int  _fd;
 250  public:
 251   fdStream(int fd = -1) : _fd(fd) { }
 252   bool is_open() const { return _fd != -1; }
 253   void set_fd(int fd) { _fd = fd; }
 254   int fd() const { return _fd; }
 255   virtual void write(const char* c, size_t len);
 256   void flush() {};
 257 };




 213   // Return number of characters written into buffer, excluding terminating zero and
 214   // subject to truncation in static buffer mode.
 215   size_t      size() const { return buffer_pos; }
 216   const char* base() const { return buffer; }
 217   void  reset();
 218   char* as_string() const;
 219 };
 220 
 221 class fileStream : public outputStream {
 222  protected:
 223   FILE* _file;
 224   bool  _need_close;
 225  public:
 226   fileStream() { _file = NULL; _need_close = false; }
 227   fileStream(const char* file_name);
 228   fileStream(const char* file_name, const char* opentype);
 229   fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
 230   ~fileStream();
 231   bool is_open() const { return _file != NULL; }
 232   virtual void write(const char* c, size_t len);
 233   size_t read(void *data, size_t size, size_t count) {
 234     assert(_file != NULL, "sanity check");
 235     return ::fread(data, size, count, _file);
 236   }
 237   char* readln(char *data, int count);
 238   int eof() { assert(_file != NULL, "sanity check"); return feof(_file); }
 239   long fileSize();
 240   void rewind() { assert(_file != NULL, "sanity check"); ::rewind(_file); }
 241   void flush();
 242 };
 243 
 244 CDS_ONLY(extern fileStream*   classlist_file;)
 245 
 246 // unlike fileStream, fdStream does unbuffered I/O by calling
 247 // open() and write() directly. It is async-safe, but output
 248 // from multiple thread may be mixed together. Used by fatal
 249 // error handler.
 250 class fdStream : public outputStream {
 251  protected:
 252   int  _fd;
 253  public:
 254   fdStream(int fd = -1) : _fd(fd) { }
 255   bool is_open() const { return _fd != -1; }
 256   void set_fd(int fd) { _fd = fd; }
 257   int fd() const { return _fd; }
 258   virtual void write(const char* c, size_t len);
 259   void flush() {};
 260 };


< prev index next >