1. 上传文件InputStream转string或bytes
private byte [] inputStreamToByte(InputStream is) throws IOException {
ByteArrayOutputStream bAOutputStream = new ByteArrayOutputStream();
int ch;
while((ch = is.read() ) != -1){
bAOutputStream.write(ch);
}
byte data [] =bAOutputStream.toByteArray();
bAOutputStream.close();
return data;
}
private String inputStreamToString(InputStream is) throws IOException {
ByteArrayOutputStream bAOutputStream = new ByteArrayOutputStream();
int ch;
while((ch = is.read() ) != -1){
bAOutputStream.write(ch);
}
String data = bAOutputStream.toString();
bAOutputStream.close();
return data;
}
2. 下载 string转 InputStream
public InputStream getInputStream() throws Exception {
return new ByteArrayInputStream(org.getFileContent().getBytes("UTF-8"));
}
注: org.getFileContent() 数据库clob类型,hibernate对应“text” ,pojo对应“String”
分享到:
相关推荐
inputStream2String, string2InputStream : inputStream 与 string 按编码互转 outputStream2String, string2OutputStream: outputStream 与 string 按编码互转 bitmap2Bytes, bytes2Bitmap : bitmap 与 byteArr 互...
Android 上传文件至服务器和下载文件至本地,亲测有效,只需传入相关参数即可。/** * android上传文件到服务器 * * @param file * 需要上传的文件 * @param RequestURL * 请求的rul * @return 返回...
* 2.String(byte[] bytes, int offset, int length, String charsetName) * 根据指定字符集将字节数组中从指定下标开始到指定长度结束的数据转换为字符串 * charsetName:字符集名 例如 : "GBK...
private String readLine(byte[] bytes, int[] index, ServletInputStream sis, String encoding) { try{ index[0]=sis.readLine(bytes, 0, bytes.length); if(index[0]){ return null; } }...
byte[] bytes = null; /** * 方法说明:获得数据连接 * 输入参数: * 返回类型:Connection 连接对象 */ try { session = getSession(); agentContext = session....
// multipart 请求, 用于文件上传: Response<String> resp = Requests.post(url).data(map).multiPart("ufile", "/path/to/file") .multiPart(..., ...).text();请求设置://禁止自动重定向 Response...
The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object. addHeader(String, String) - Method in interface javax.servlet....
文件的加密与解密 第 章 加密与解密技术 第19章 加密与解密技术 829 19.1 数据的加密与解密 实例571 异或算法对数字进行加密与解密 光盘位置:光盘\MR\19\571 中级 趣味指数: 实 例说明 在实现本实例之前先来简要...
String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim(); if (cmd.indexOf("wmic.exe") >= 0) { continue; } // log.info("line="+line); if (!caption.equals("javaw.exe")) { ...
* Minimum value should be over 10000 bytes. * @param size -1 means maximum buffer size available. */ public void setLineBufferSize(int size) { lineBufferSize = size; } /** * Return ...
static boolean saveBitmap2file(Bitmap bmp,String filename){ CompressFormat format= Bitmap.CompressFormat.JPEG; int quality = 100; OutputStream stream = null; try { stream = new FileOutputStream("/...
* @param InputStream containing GIF file. * @return read status code (0 = no errors) */ public int read(InputStream is) { init(); if (is != null) { if (!(is instanceof BufferedInputStream)) is...