Java InputStream Create getInputStream(String data)

Here you can find the source of getInputStream(String data)

Description

returns an input stream that will give you back the specified string

License

Open Source License

Parameter

Parameter Description
data the stream data

Return

the input stream

Declaration


public static InputStream getInputStream(String data) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.InputStream;
import java.io.EOFException;

public class Main {
    /**/*from   w  w w.j  a v  a2 s  . c  om*/
     *  returns an input stream that will give you
     *  back the specified string
     * 
     *  @param data the stream data
     *  @return the input stream
     * 
     */

    public static InputStream getInputStream(String data) {

        final String theData = data;

        return new InputStream() {
            final String data = theData;
            int position = 0;

            public int read() throws EOFException {
                if (position < data.length())
                    return data.charAt(position++);
                return -1;
            }

            @Override
            public int available() {
                return data.length() - position; // include terminating -1
            }
        };

    }
}

Related

  1. getInputStream(final File file, final boolean createFile)
  2. getInputStream(final Serializable obj)
  3. getInputStream(final String fileName)
  4. getInputStream(final String sourceFolder, final Class clazz)
  5. getInputStream(String content)
  6. getInputStream(String fileName)
  7. getInputStream(String fileName)
  8. getInputStream(String fileName)
  9. getInputStream(String filename)