1.inputStream流写数据到本地
public static void inoutStreamToLocal(InputStream inputStream,String filePath){
try{
FileOutputStream outputStream = new FileOutputStream(filePath);
byte[] buffer = new byte[1024];
int length;
while((length=inputStream.read(buffer))!=-1){
outputStream.write(buffer,0,length);
}
}catch (IOException e){
throw new RuntimeException(e);
}finally {
if(outputStream!=null){
outputStream.close
}
}
}
2.inputStream流转化为byte[]
public static void inoutStreamTobyte(InputStream inputStream){
try{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while((length=inputStream.read(buffer))!=-1){
outputStream.write(buffer,0,length);
}
return outputStream.toByteArray();
}catch (IOException e){
throw new RuntimeException(e);
}finally {
if(outputStream!=null){
outputStream.close
}
}
}
3.BuffferedReader流转化为inputStream流
public static void inoutStreamTobyte(BuffferedReader buffferedReader){
return new InputStream(){
@Override
public int read() throw IOException{
try {
return buffferedReader.read();
}catch (Exception e){
e.printStackTrace();
return -1;
}
}
}
}
4.图片流数据转化为base64供使用
public static void inoutStreamToImageIO(InputStream inputStream){
BufferedImage bufferedImage = ImageIO.read(inputStream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage,"png",outputStream)
String base64Str = Base64Utils.encodeToString(ots.toByteArray);
}