当前位置: 首页>>代码示例>>Java>>正文


Java StreamUtil.close方法代码示例

本文整理汇总了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;
}
 
开发者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: 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

示例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;
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:25,代码来源:ObjectUtil.java

示例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);
	}
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:21,代码来源:ObjectUtil.java

示例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;
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:23,代码来源:ObjectUtil.java

示例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);
    }
}
 
开发者ID:bentolor,项目名称:microframeworks-showcase,代码行数:24,代码来源:JsonResultRenderer.java

示例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;
}
 
开发者ID:febit,项目名称:febit,代码行数:16,代码来源:TempFileResult.java

示例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;
}
 
开发者ID:febit,项目名称:febit-common,代码行数:14,代码来源:ClassUtil.java

示例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();
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:15,代码来源:ExceptionUtil.java

示例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();
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:ExceptionUtil.java

示例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);
	}
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:PropertiesUtil.java

示例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);
	}
}
 
开发者ID:indic-ocr,项目名称:LibreOCR,代码行数:17,代码来源:PropertiesUtil.java


注:本文中的jodd.io.StreamUtil.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。