Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.fujitsu.iflow.model.util
Class StringUTF8InputStream

    java.lang.Object
      java.io.InputStream
          com.fujitsu.iflow.model.util.StringUTF8InputStream

public class StringUTF8InputStream
extends java.io.InputStream

StringUTF8InputStream This is a *proper* conversion from UTF-16 string to UTF-8 byte stream. A string with full Unicode characters can be streamed out as UTF-8 bytes. It performs the conversion on the fly, without needing any large byte buffer internally. Only supports UTF-8 -- there is no need for any others. Here is why: The only reason you would use this is because you have some sort of routine that needs an input stream, but you have the data as a String. The routine that reads the input stream needs to be able to read different kinds of byte encodings, so you should be able to specify UTF-8. UTF-8 is the ONLY encoding that guarantees that all characters in the UTF-16 can be expressed without loss of characters. Since Java strings are always UTF-16, and you can always specify UTF-8 for the thing that consumes the input stream, you can come to the conclusion that you always should use always use UTF-8 for this temporary intermediate stream. In spite of that logic, some might still insist that this class is more general if it had a parameters to specify the encoding to use. This would greatly slow down the operation of the class, because knowledge of UTF-8 encoding is used to keep the amount of memory low, and to make the conversion very fast. Mark is not supported because you might try to mark in the middle of a multi-byte sequence, and the sequence would have to be stored away. Have not worked through all the implications of this, so for now not supported.

Constructor Summary
`StringUTF8InputStream(java.io.Reader source)` Composes an InputStream stream from any other Reader you may have around.
`StringUTF8InputStream(java.lang.String source)` Composes a stream from a String

Method Summary
`void` | `close()` Closes the Stringreader.
`void` | `mark(int limit)` Marks the read limit of the StringReader.
`boolean` | `markSupported()`
`int` | `read()` Reads from the Stringreader.
`void` | `reset()` Resets the StringReader.

Methods inherited from class java.io.InputStream
`available, read, read, skip`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StringUTF8InputStream

    public StringUTF8InputStream(java.lang.String source)

  Composes a stream from a String

Parameters:
  `source` - The string to read from. Must not be `null`.

### StringUTF8InputStream

    public StringUTF8InputStream(java.io.Reader source)

  Composes an InputStream stream from any other Reader you may have around.

Parameters:
  `source` - The Reader object to read from. Must not be `null`.

Method Detail

### read

    public int read()
             throws java.io.IOException

  Reads from the Stringreader. If the value is less than 128 it is returned directly, because UTF-8 encoding is this way. If more than 127 the character is broken into a multibyte sequence which will be returned over 2 or more subsequent reads.

  Returns:
    the value of the next byte of the UTF-8 stream, or -1 if there is nothing left in the original string.
  Throws:
    `java.io.IOException` - if the original StringReader fails to be read

### close

    public void close()
               throws java.io.IOException

  Closes the Stringreader.

  Throws:
    `java.io.IOException` - if the original Reader fails to be closed

### mark

    public void mark(int limit)

  Marks the read limit of the StringReader.

  Parameters:
    `limit` - the maximum limit of bytes that can be read before the mark position becomes invalid

### reset

    public void reset()
               throws java.io.IOException

  Resets the StringReader.

  Throws:
    `java.io.IOException` - if the StringReader fails to be reset

### markSupported

    public boolean markSupported()

  See Also:
    `InputStream.markSupported()`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD