Java InputStream Create inputStream(final String in)

Here you can find the source of inputStream(final String in)

Description

Makes an input stream from a String.

License

Open Source License

Declaration

public static InputStream inputStream(final String in) 

Method Source Code


//package com.java2s;
//    it under the terms of the GNU General Public License as published by

import java.io.IOException;
import java.io.InputStream;

public class Main {
    /**//w  ww  .ja  v a 2s .c om
     * Makes an input stream from a String.
     * 
     * BytesArrayInputStream is bugged. Use this instead.
     * 
     */
    public static InputStream inputStream(final String in) {
        return new InputStream() {
            int charindex = 0;

            public synchronized int read() throws IOException {
                if (charindex < in.length()) {
                    return (int) in.charAt(charindex++);
                } else
                    return -1;
            }
        };
    }
}

Related

  1. getInputStream(String url)
  2. getInputStream(String xmlStr)
  3. getInputStream(String... subpaths)
  4. getInputStream(String[] args)
  5. inputStream(final File file)
  6. inputStream(String fileName)
  7. inputStream(String path)
  8. inputStreamFromPath(String path)
  9. InputStreamFromString(String str)