All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docshare.util.IOUtil Maven / Gradle / Ivy

Go to download

An efficient, fast, convenient, easy to learn, easy to use MVC framework and ORM framework. It is seamless compatible with JSTL and supports FreeMarker. It can run independently, and it can also be applied to traditional Java Web projects. It is an efficient, fast, convenient, easy to learn and easy to use MVC framework and ORM framework. It is seamless compatible with JSTL and supports FreeMarker. It can be run on its own, or it can be applied to traditional Java Web projects

There is a newer version: 2023.06.19
Show newest version
package org.docshare.util;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import org.docshare.log.Log;

public class IOUtil {
	public static String readStream(InputStream in){
		return readStream(in,"utf-8");
	}
	public static String readStream(InputStream in,String charset){
//		Scanner sc = new Scanner(in,charset);
//		StringBuilder sb =new StringBuilder();
//		while(sc.hasNextLine()){
//			sb.append(sc.nextLine());
//			sb.append('\n');
//		}
		ByteArrayOutputStream bos=null;
        try {
			byte[] buffer = new byte[1024];
			int len;
			 bos = new ByteArrayOutputStream();
			while((len = in.read(buffer)) != -1) {
			    bos.write(buffer, 0, len);
			}
			return new String(bos.toByteArray(),charset);
		} catch (Exception e) {
			Log.e(e);
			return "";
		}finally {
			FileTool.safelyClose(bos);
		}
		
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy