org.apache.solr.common.util

## Class ContentStreamBase.StringStream

- java.lang.Object
- - org.apache.solr.common.util.ContentStreamBase
  - - org.apache.solr.common.util.ContentStreamBase.StringStream

- All Implemented Interfaces:
    ContentStream
  Enclosing class:
    ContentStreamBase

      public static class ContentStreamBase.StringStream
      extends ContentStreamBase

  Construct a `ContentStream` from a `String`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.solr.common.util.ContentStreamBase

      `ContentStreamBase.ByteArrayStream, ContentStreamBase.FileStream, ContentStreamBase.StringStream, ContentStreamBase.URLStream`

  - ### Field Summary

    - ### Fields inherited from class org.apache.solr.common.util.ContentStreamBase

      `contentType, DEFAULT_CHARSET, name, size, sourceInfo`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StringStream(String str)`
    `StringStream(String str, String contentType)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `detect(String str)`
    `Reader` | `getReader()` If an charset is defined (by the contentType) use that, otherwise use a StringReader
    `InputStream` | `getStream()` Get an open stream.

    - ### Methods inherited from class org.apache.solr.common.util.ContentStreamBase

      `getCharsetFromContentType, getContentType, getName, getSize, getSourceInfo, setContentType, setName, setSize, setSourceInfo`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### StringStream

          public StringStream(String str)

    - #### StringStream

          public StringStream(String str,
                              String contentType)

  - ### Method Detail

    - #### detect

          public static String detect(String str)

    - #### getStream

          public InputStream getStream()
                                throws IOException

      Description copied from interface: `ContentStream`
      Get an open stream. You are responsible for closing it. Consider using something like:

             InputStream stream = stream.getStream();
             try {
               // use the stream...
             }
             finally {
               IOUtils.closeQuietly(stream);
             }

      Only the first call to `getStream()` or `getReader()` is guaranteed to work. The runtime behavior for additional calls is undefined. Note: you must call `getStream()` or `getReader()` before the attributes (name, contentType, etc) are guaranteed to be set. Streams may be lazy loaded only when this method is called.
      Throws:
        `IOException`

    - #### getReader

          public Reader getReader()
                           throws IOException

      If an charset is defined (by the contentType) use that, otherwise use a StringReader
      Specified by:
        `getReader` in interface `ContentStream`
      Overrides:
        `getReader` in class `ContentStreamBase`
      Throws:
        `IOException`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.