< prev index next >

src/hotspot/share/utilities/ostream.hpp

Print this page
rev 59275 : [mq]: v1
   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 198   size_t buffer_length;
 199   bool   buffer_fixed;
 200 
 201   // zero terminate at buffer_pos.
 202   void zero_terminate();
 203 
 204  public:
 205   // Create a stringStream using an internal buffer of initially initial_bufsize size;
 206   // will be enlarged on demand. There is no maximum cap.
 207   stringStream(size_t initial_bufsize = 256);
 208   // Creates a stringStream using a caller-provided buffer. Will truncate silently if
 209   // it overflows.
 210   stringStream(char* fixed_buffer, size_t fixed_buffer_size);
 211   ~stringStream();
 212   virtual void write(const char* c, size_t len);
 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();


   1 /*
   2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 198   size_t buffer_length;
 199   bool   buffer_fixed;
 200 
 201   // zero terminate at buffer_pos.
 202   void zero_terminate();
 203 
 204  public:
 205   // Create a stringStream using an internal buffer of initially initial_bufsize size;
 206   // will be enlarged on demand. There is no maximum cap.
 207   stringStream(size_t initial_bufsize = 256);
 208   // Creates a stringStream using a caller-provided buffer. Will truncate silently if
 209   // it overflows.
 210   stringStream(char* fixed_buffer, size_t fixed_buffer_size);
 211   ~stringStream();
 212   virtual void write(const char* c, size_t len);
 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   // copy to a resource, or C-heap, array as requested
 219   char* as_string(bool c_heap = false) const;
 220 };
 221 
 222 class fileStream : public outputStream {
 223  protected:
 224   FILE* _file;
 225   bool  _need_close;
 226  public:
 227   fileStream() { _file = NULL; _need_close = false; }
 228   fileStream(const char* file_name);
 229   fileStream(const char* file_name, const char* opentype);
 230   fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
 231   ~fileStream();
 232   bool is_open() const { return _file != NULL; }
 233   virtual void write(const char* c, size_t len);
 234   size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
 235   char* readln(char *data, int count);
 236   int eof() { return feof(_file); }
 237   long fileSize();
 238   void rewind() { ::rewind(_file); }
 239   void flush();


< prev index next >