本文整理了Java中com.twelvemonkeys.io.FileUtil.close()
方法的一些代码示例,展示了FileUtil.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.close()
方法的具体详情如下:
包路径:com.twelvemonkeys.io.FileUtil
类名称:FileUtil
方法名:close
[英]Tries to close the given stream. NOTE: If the stream cannot be closed, the IOException thrown is silently ignored.
[中]尝试关闭给定的流。注意:如果无法关闭流,则会自动忽略引发的IOException。
代码示例来源:origin: haraldk/TwelveMonkeys
/**
* Writes the contents from a byte array to a file.
*
* @param pFile The file to write to
* @param pData The byte array to write
* @return {@code true}, otherwise an IOException is thrown.
* @throws IOException if an i/o error occurs during write.
*/
public static boolean write(File pFile, byte[] pData) throws IOException {
boolean success = false;
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(pFile));
success = write(out, pData);
}
finally {
close(out);
}
return success;
}
代码示例来源:origin: haraldk/TwelveMonkeys
@SuppressWarnings("SameParameterValue")
private static ICC_Profile readProfileFromClasspathResource(final String profilePath) {
InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath);
if (stream != null) {
if (DEBUG) {
System.out.println("Loading profile from classpath resource: " + profilePath);
}
try {
return ICC_Profile.getInstance(stream);
}
catch (IOException ignore) {
if (DEBUG) {
ignore.printStackTrace();
}
}
finally {
FileUtil.close(stream);
}
}
return null;
}
代码示例来源:origin: haraldk/TwelveMonkeys
/**
* Gets the contents of the given file, as a byte array.
*
* @param pFile the file to get content from
* @return the content of the file as a byte array.
* @throws IOException if the read operation fails
*/
public static byte[] read(File pFile) throws IOException {
// Custom implementation, as we know the size of a file
if (!pFile.exists()) {
throw new FileNotFoundException(pFile.toString());
}
byte[] bytes = new byte[(int) pFile.length()];
InputStream in = null;
try {
// Use buffer size two times byte array, to avoid i/o bottleneck
in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2);
int off = 0;
int len;
while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) {
off += len;
// System.out.println("read:" + len);
}
}
// Just pass any IOException on up the stack
finally {
close(in);
}
return bytes;
}
代码示例来源:origin: haraldk/TwelveMonkeys
FileUtil.close(reader);
代码示例来源:origin: haraldk/TwelveMonkeys
close(in);
close(out);
代码示例来源:origin: haraldk/TwelveMonkeys
FileUtil.close(reader);
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-io
/**
* Writes the contents from a byte array to a file.
*
* @param pFile The file to write to
* @param pData The byte array to write
* @return {@code true}, otherwise an IOException is thrown.
* @throws IOException if an i/o error occurs during write.
*/
public static boolean write(File pFile, byte[] pData) throws IOException {
boolean success = false;
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(pFile));
success = write(out, pData);
}
finally {
close(out);
}
return success;
}
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.imageio/imageio-core
private static ICC_Profile readProfileFromClasspathResource(final String profilePath) {
InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath);
if (stream != null) {
if (DEBUG) {
System.out.println("Loading profile from classpath resource: " + profilePath);
}
try {
return ICC_Profile.getInstance(stream);
}
catch (IOException ignore) {
if (DEBUG) {
ignore.printStackTrace();
}
}
finally {
FileUtil.close(stream);
}
}
return null;
}
代码示例来源:origin: com.twelvemonkeys/twelvemonkeys-core
/**
* Writes the contents from a byte array to a file.
*
* @param pFile The file to write to
* @param pData The byte array to write
* @return {@code true}, otherwise an IOException is thrown.
* @throws IOException if an i/o error occurs during write.
*/
public static boolean write(File pFile, byte[] pData) throws IOException {
boolean success = false;
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(pFile));
success = write(out, pData);
}
finally {
close(out);
}
return success;
}
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-io
/**
* Gets the contents of the given file, as a byte array.
*
* @param pFile the file to get content from
* @return the content of the file as a byte array.
* @throws IOException if the read operation fails
*/
public static byte[] read(File pFile) throws IOException {
// Custom implementation, as we know the size of a file
if (!pFile.exists()) {
throw new FileNotFoundException(pFile.toString());
}
byte[] bytes = new byte[(int) pFile.length()];
InputStream in = null;
try {
// Use buffer size two times byte array, to avoid i/o bottleneck
in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2);
int off = 0;
int len;
while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) {
off += len;
// System.out.println("read:" + len);
}
}
// Just pass any IOException on up the stack
finally {
close(in);
}
return bytes;
}
代码示例来源:origin: com.twelvemonkeys/twelvemonkeys-core
/**
* Gets the contents of the given file, as a byte array.
*
* @param pFile the file to get content from
* @return the content of the file as a byte array.
* @throws IOException if the read operation fails
*/
public static byte[] read(File pFile) throws IOException {
// Custom implementation, as we know the size of a file
if (!pFile.exists()) {
throw new FileNotFoundException(pFile.toString());
}
byte[] bytes = new byte[(int) pFile.length()];
InputStream in = null;
try {
// Use buffer size two times byte array, to avoid i/o bottleneck
in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2);
int off = 0;
int len;
while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) {
off += len;
// System.out.println("read:" + len);
}
}
// Just pass any IOException on up the stack
finally {
close(in);
}
return bytes;
}
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-io
FileUtil.close(reader);
代码示例来源:origin: com.twelvemonkeys/twelvemonkeys-core
FileUtil.close(reader);
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-io
close(in);
close(out);
代码示例来源:origin: com.twelvemonkeys/twelvemonkeys-core
close(in);
close(out);
代码示例来源:origin: com.twelvemonkeys/twelvemonkeys-core
FileUtil.close(reader);
代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-io
FileUtil.close(reader);
内容来源于网络,如有侵权,请联系作者删除!