Package totalcross.io

Class Stream

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static byte[] skipBuffer  
    • Constructor Summary

      Constructors 
      Constructor Description
      Stream()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.io.InputStream asInputStream()  
      java.io.OutputStream asOutputStream()  
      static Stream asStream​(java.io.InputStream inputStream)  
      static Stream asStream​(java.io.OutputStream outputStream)  
      abstract void close()
      Closes this I/O connection, releasing any associated resources.
      abstract int readBytes​(byte[] buf, int start, int count)
      Reads bytes from the stream.
      int skipBytes​(int n)
      Skips over and discards n bytes of data from this stream.
      java.io.InputStream wrapInputStream()
      Deprecated.
      use asInputStream() instead
      static Stream wrapInputStreamToStream​(java.io.InputStream inputStream)
      Deprecated.
      int write​(int b)
      Writes a single byte to the stream.
      int writeBytes​(byte[] buf)
      Writes bytes to the stream.
      abstract int writeBytes​(byte[] buf, int start, int count)
      Writes bytes to the stream.
      int writeBytes​(java.lang.String string)
      Writes the string to the stream as a byte array.
      int writeBytes​(java.lang.StringBuffer sb)
      Writes the given StringBuffer as a byte array, retrieved using Convert.getBytes.
      The String is written as-is, nothing is placed before or after it.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • skipBuffer

        protected static byte[] skipBuffer
    • Constructor Detail

      • Stream

        public Stream()
    • Method Detail

      • readBytes

        public abstract int readBytes​(byte[] buf,
                                      int start,
                                      int count)
                               throws IOException
        Reads bytes from the stream. Returns the number of bytes actually read or -1 if the end of the stream was reached. (if applicable to the stream)
        Parameters:
        buf - the byte array to read data into
        start - the start position in the array
        count - the number of bytes to read
        Throws:
        IOException
      • writeBytes

        public abstract int writeBytes​(byte[] buf,
                                       int start,
                                       int count)
                                throws IOException
        Writes bytes to the stream. Returns the number of bytes actually written or throws an IOException if an error prevented the write operation from occurring.
        Parameters:
        buf - the byte array to write data from
        start - the start position in the byte array
        count - the number of bytes to write
        Returns:
        the number of bytes actually written
        Throws:
        IOException
      • writeBytes

        public int writeBytes​(byte[] buf)
                       throws IOException
        Writes bytes to the stream. Returns the number of bytes actually written or throws an IOException if an error prevented the write operation from occurring.
        Parameters:
        buf - the byte array to write data from
        Returns:
        the number of bytes actually written
        Throws:
        IOException
      • writeBytes

        public int writeBytes​(java.lang.String string)
                       throws IOException
        Writes the string to the stream as a byte array. Returns the number of bytes actually written or throws an IOException if an error prevented the write operation from occurring.
        The String is written as-is, nothing is placed before or after it.
        Parameters:
        string - the string whose bytes will be written
        Returns:
        the number of bytes actually written
        Throws:
        IOException
      • writeBytes

        public final int writeBytes​(java.lang.StringBuffer sb)
                             throws IOException
        Writes the given StringBuffer as a byte array, retrieved using Convert.getBytes.
        The String is written as-is, nothing is placed before or after it.
        Parameters:
        sb - the StringBuffer to get the bytes from
        Returns:
        the number of bytes actually written
        Throws:
        IOException
        Since:
        TotalCross 1.23
      • write

        public int write​(int b)
                  throws IOException
        Writes a single byte to the stream.
        Parameters:
        b - the byte to write (only least significant byte is written)
        Returns:
        the number of bytes actually written
        Throws:
        IOException
        Since:
        TotalCross 4.1.1
      • skipBytes

        public int skipBytes​(int n)
                      throws IOException
        Skips over and discards n bytes of data from this stream. The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped, but this may vary among some implementations of skipBytes in classes that inherit them (like File and PDBFile).

        The skip method of this class uses a static byte array, repeatedly reading into it until n bytes have been read or the end of the stream has been reached. Subclasses are encouraged to provide a more efficient implementation of this method. For instance, the implementation may depend on the ability to seek.
        Parameters:
        n - the number of bytes to be skipped.
        Returns:
        the actual number of bytes skipped.
        Throws:
        IOException - if the stream does not support skip, or if some other I/O error occurs.
      • wrapInputStream

        @Deprecated
        public java.io.InputStream wrapInputStream()
        Deprecated.
        use asInputStream() instead
      • asInputStream

        public java.io.InputStream asInputStream()
      • asOutputStream

        public java.io.OutputStream asOutputStream()
      • wrapInputStreamToStream

        @Deprecated
        public static Stream wrapInputStreamToStream​(java.io.InputStream inputStream)
        Deprecated.
      • asStream

        public static Stream asStream​(java.io.InputStream inputStream)
      • asStream

        public static Stream asStream​(java.io.OutputStream outputStream)
      • close

        public abstract void close()
                            throws IOException
        Closes this I/O connection, releasing any associated resources. Once closed a connection is no longer valid.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        IOException - If an I/O error occurs.