本文整理汇总了Java中jodd.io.StreamUtil类的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil类的具体用法?Java StreamUtil怎么用?Java StreamUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StreamUtil类属于jodd.io包,在下文中一共展示了StreamUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: render
import jodd.io.StreamUtil; //导入依赖的package包/类
@Override
public Object render(ActionRequest actionRequest) throws IOException {
HttpServletResponse response = actionRequest.response;
if (etag != null) {
response.setHeader("Etag", etag);
}
ServletUtil.prepareResponse(response, downloadFileName, mimeType, length);
InputStream contentInputStream = this.inputStream;
OutputStream out = response.getOutputStream();
StreamUtil.copy(contentInputStream, out);
out.flush();
StreamUtil.close(contentInputStream);
return null;
}
开发者ID:febit,项目名称:febit,代码行数:19,代码来源:RawResult.java
示例2: render
import jodd.io.StreamUtil; //导入依赖的package包/类
@Override
public Object render(ActionRequest actionRequest, CaptchaData resultValue) throws Exception {
final HttpServletResponse response = actionRequest.response;
final HttpSession session = actionRequest.request.getSession();
final String capText = captcha.createText();
resultValue.setCode(capText);
session.setAttribute(resultValue.getSessionKey(), resultValue);
ServletUtil.preventCaching(response);
response.setContentType("image/jpg");
OutputStream out = null;
try {
captcha.write(capText, out = response.getOutputStream());
} catch (IOException e) {
throw new RuntimeException("Exception when create captcha image ", e);
} finally {
StreamUtil.close(out);
}
return null;
}
开发者ID:febit,项目名称:febit,代码行数:22,代码来源:CaptchaRender.java
示例3: convert
import jodd.io.StreamUtil; //导入依赖的package包/类
public File convert(Object value) {
if (value instanceof FileUpload) {
FileUpload fileUpload = (FileUpload) value;
InputStream in = null;
try {
in = fileUpload.getFileInputStream();
File tempFile = FileUtil.createTempFile();
FileUtil.writeStream(tempFile, in);
return tempFile;
} catch (IOException ioex) {
return null;
} finally {
StreamUtil.close(in);
}
}
return null;
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:22,代码来源:FileUploadToFileTypeConverter.java
示例4: processStream
import jodd.io.StreamUtil; //导入依赖的package包/类
@Override
protected void processStream() throws IOException {
file = new File(destFolder, header.getFileName());
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
size = 0;
try {
if (maxFileSize == -1) {
size = input.copyAll(out);
} else {
size = input.copyMax(out, maxFileSize + 1); // one more byte to detect larger files
if (size > maxFileSize) {
fileTooBig = true;
valid = false;
input.skipToBoundary();
return;
}
}
valid = true;
} finally {
StreamUtil.close(out);
}
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:23,代码来源:DiskFileUpload.java
示例5: unzip
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Unzips GZip-ed body content, removes the content-encoding header
* and sets the new content-length value.
*/
public HttpResponse unzip() {
String contentEncoding = contentEncoding();
if (contentEncoding != null && contentEncoding().equals("gzip")) {
if (body != null) {
removeHeader(HEADER_CONTENT_ENCODING);
try {
ByteArrayInputStream in = new ByteArrayInputStream(body.getBytes(StringPool.ISO_8859_1));
GZIPInputStream gzipInputStream = new GZIPInputStream(in);
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtil.copy(gzipInputStream, out);
body(out.toString(StringPool.ISO_8859_1));
} catch (IOException ioex) {
throw new HttpException(ioex);
}
}
}
return this;
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:27,代码来源:HttpResponse.java
示例6: writeTo
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Writes content to the writer.
*/
public void writeTo(Writer writer) throws IOException {
for (Object o : list) {
if (o instanceof FastByteBuffer) {
FastByteBuffer fastByteBuffer = (FastByteBuffer) o;
byte[] array = fastByteBuffer.toArray();
writer.write(new String(array, StringPool.ISO_8859_1));
}
else if (o instanceof Uploadable) {
Uploadable uploadable = (Uploadable) o;
InputStream inputStream = uploadable.openInputStream();
try {
StreamUtil.copy(inputStream, writer, StringPool.ISO_8859_1);
}
finally {
StreamUtil.close(inputStream);
}
}
}
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:27,代码来源:Buffer.java
示例7: cloneViaSerialization
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Create object copy using serialization mechanism.
*/
public static <T extends Serializable> T cloneViaSerialization(T obj) throws IOException, ClassNotFoundException {
FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
ObjectOutputStream out = null;
ObjectInputStream in = null;
Object objCopy = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(obj);
out.flush();
byte[] bytes = bos.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(bytes));
objCopy = in.readObject();
} finally {
StreamUtil.close(out);
StreamUtil.close(in);
}
return (T) objCopy;
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:25,代码来源:ObjectUtil.java
示例8: writeObject
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Writes serializable object to a file. Existing file will be overwritten.
*/
public static void writeObject(File dest, Object object) throws IOException {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
ObjectOutputStream oos = null;
try {
fos = new FileOutputStream(dest);
bos = new BufferedOutputStream(fos);
oos = new ObjectOutputStream(bos);
oos.writeObject(object);
} finally {
StreamUtil.close(oos);
StreamUtil.close(bos);
StreamUtil.close(fos);
}
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:21,代码来源:ObjectUtil.java
示例9: readObject
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Reads serialized object from the file.
*/
public static Object readObject(File source) throws IOException, ClassNotFoundException {
Object result = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
ObjectInputStream ois = null;
try {
fis = new FileInputStream(source);
bis = new BufferedInputStream(fis);
ois = new ObjectInputStream(bis);
result = ois.readObject();
} finally {
StreamUtil.close(ois);
StreamUtil.close(bis);
StreamUtil.close(fis);
}
return result;
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:23,代码来源:ObjectUtil.java
示例10: render
import jodd.io.StreamUtil; //导入依赖的package包/类
@Override
public void render(ActionRequest request, JsonResult jsonResult) throws Exception {
HttpServletResponse response = request.getHttpServletResponse();
response.setContentType(MimeTypes.MIME_APPLICATION_JSON);
if (jsonResult.getStatus() > 0) {
response.setStatus(jsonResult.getStatus());
}
PrintWriter writer = null;
try {
writer = response.getWriter();
String result;
try {
result = objectMapper.writeValueAsString(jsonResult.getModel());
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Invalid JSON to render");
}
writer.println(result);
} finally {
StreamUtil.close(writer);
}
}
开发者ID:bentolor,项目名称:microframeworks-showcase,代码行数:24,代码来源:JsonResultRenderer.java
示例11: readInput
import jodd.io.StreamUtil; //导入依赖的package包/类
protected static char[] readInput(HttpServletRequest request) {
try {
return StreamUtil.readChars(request.getInputStream(), StringPool.UTF_8);
} catch (Exception e) {
LOG.error("READ_DATA_ERROR:", e);
return null;
}
}
开发者ID:febit,项目名称:febit,代码行数:9,代码来源:MessageUtil.java
示例12: render
import jodd.io.StreamUtil; //导入依赖的package包/类
@Override
public Object render(ActionRequest actionRequest) throws IOException {
HttpServletResponse response = actionRequest.response;
if (etag != null) {
response.setHeader("Etag", etag);
}
ServletUtil.prepareResponse(response, downloadFileName, mimeType, length);
InputStream contentInputStream = new FileInputStream(file);
OutputStream out = response.getOutputStream();
StreamUtil.copy(contentInputStream, out);
out.flush();
StreamUtil.close(contentInputStream);
file.delete();
return null;
}
开发者ID:febit,项目名称:febit,代码行数:16,代码来源:TempFileResult.java
示例13: readResourceToString
import jodd.io.StreamUtil; //导入依赖的package包/类
public static String readResourceToString(String path, String encoding) {
InputStream input = openResourceStream(path);
if (input == null) {
return null;
}
try {
return new String(StreamUtil.readChars(input, encoding));
} catch (IOException ignore) {
} finally {
StreamUtil.close(input);
}
return null;
}
开发者ID:febit,项目名称:febit-common,代码行数:14,代码来源:ClassUtil.java
示例14: exceptionStackTraceToString
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Prints stack trace into a String.
*/
public static String exceptionStackTraceToString(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
t.printStackTrace(pw);
StreamUtil.close(pw);
StreamUtil.close(sw);
return sw.toString();
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:15,代码来源:ExceptionUtil.java
示例15: exceptionChainToString
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Prints full exception stack trace, from top to root cause, into a String.
*/
public static String exceptionChainToString(Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
while (t != null) {
t.printStackTrace(pw);
t = t.getCause();
}
StreamUtil.close(pw);
StreamUtil.close(sw);
return sw.toString();
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:ExceptionUtil.java
示例16: loadFromFile
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Loads properties from the file. Properties are appended to the existing
* properties object.
*
* @param p properties to fill in
* @param file file to read properties from
*/
public static void loadFromFile(Properties p, File file) throws IOException {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
p.load(fis);
} finally {
StreamUtil.close(fis);
}
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:PropertiesUtil.java
示例17: writeToFile
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Writes properties to a file.
*
* @param p properties to write to file
* @param file destination file
* @param header optional header
*/
public static void writeToFile(Properties p, File file, String header) throws IOException {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
p.store(fos, header);
} finally {
StreamUtil.close(fos);
}
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:PropertiesUtil.java
示例18: objectToByteArray
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Serialize an object to byte array.
*/
public static byte[] objectToByteArray(Object obj) throws IOException {
FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(bos);
oos.writeObject(obj);
} finally {
StreamUtil.close(oos);
}
return bos.toByteArray();
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:16,代码来源:ObjectUtil.java
示例19: byteArrayToObject
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* De-serialize an object from byte array.
*/
public static Object byteArrayToObject(byte[] data) throws IOException, ClassNotFoundException {
Object retObj = null;
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(bais);
retObj = ois.readObject();
} finally {
StreamUtil.close(ois);
}
return retObj;
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:ObjectUtil.java
示例20: isTypeSignatureInUse
import jodd.io.StreamUtil; //导入依赖的package包/类
/**
* Returns <code>true</code> if class contains {@link #getTypeSignatureBytes(Class) type signature}.
* It searches the class content for bytecode signature. This is the fastest way of finding if come
* class uses some type. Please note that if signature exists it still doesn't means that class uses
* it in expected way, therefore, class should be loaded to complete the scan.
*/
protected boolean isTypeSignatureInUse(InputStream inputStream, byte[] bytes) {
try {
byte[] data = StreamUtil.readBytes(inputStream);
int index = ArraysUtil.indexOf(data, bytes);
return index != -1;
} catch (IOException ioex) {
throw new FindFileException("Read error", ioex);
}
}
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:16,代码来源:ClassFinder.java
注:本文中的jodd.io.StreamUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论