|
|
@ -72,6 +72,29 @@ public class FileUtil { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] read(InputStream is) { |
|
|
|
|
|
|
|
byte[] body = null; |
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
byte[] buf = new byte[20480]; |
|
|
|
|
|
|
|
int len = -1; |
|
|
|
|
|
|
|
while ((len = is.read(buf)) != -1) { |
|
|
|
|
|
|
|
if(body == null) { |
|
|
|
|
|
|
|
body = new byte[len]; |
|
|
|
|
|
|
|
System.arraycopy(buf, 0, body, 0, len); |
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
|
|
byte[] tmp = body; |
|
|
|
|
|
|
|
body = new byte[len + tmp.length]; |
|
|
|
|
|
|
|
System.arraycopy(tmp, 0, body, 0, tmp.length); |
|
|
|
|
|
|
|
System.arraycopy(buf, 0, body, tmp.length, len); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return body; |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
log.error("Read file error.", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Read file and return content in string; |
|
|
|
* Read file and return content in string; |
|
|
|
* @param file |
|
|
|
* @param file |
|
|
|