本文整理汇总了Java中jodd.io.StreamUtil.close方法的典型用法代码示例。如果您正苦于以下问题:Java StreamUtil.close方法的具体用法?Java StreamUtil.close怎么用?Java StreamUtil.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jodd.io.StreamUtil
的用法示例。
在下文中一共展示了StreamUtil.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例5: 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);
}
}
}
}
示例6: 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;
}
示例7: 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);
}
}
示例8: 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;
}
示例9: 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);
}
}
示例10: 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;
}
示例11: 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;
}
示例12: 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();
}
示例13: 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();
}
示例14: 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);
}
}
示例15: 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);
}
}