Android String to InputStream Convert convertToInputStream(String string)

Here you can find the source of convertToInputStream(String string)

Description

convert To Input Stream

Declaration

public static InputStream convertToInputStream(String string) 

Method Source Code

//package com.java2s;
import android.graphics.Bitmap;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class Main {
    public static InputStream convertToInputStream(String string) {
        byte[] bytes = string.getBytes();
        return new ByteArrayInputStream(bytes);
    }//from  w  w  w. j av  a 2  s.  c  o  m

    public static InputStream convertToInputStream(Bitmap bitmap) {
        ByteArrayOutputStream expectedOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/,
                expectedOutputStream);
        byte[] expectedBitmapData = expectedOutputStream.toByteArray();
        return new ByteArrayInputStream(expectedBitmapData);
    }
}

Related

  1. StringTOInputStream(String in)
  2. StringTOInputStream(String in)
  3. StringTOInputStream(String in)
  4. StringTOInputStream(String in, String encoding)
  5. StringTOInputStream(String str)