本文整理了Java中org.apache.nifi.util.file.FileUtils.closeQuietly()
方法的一些代码示例,展示了FileUtils.closeQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.closeQuietly()
方法的具体详情如下:
包路径:org.apache.nifi.util.file.FileUtils
类名称:FileUtils
方法名:closeQuietly
[英]Closes the given closeable quietly - no logging, no exceptions...
[中]安静地关闭给定的可关闭文件-无日志记录,无异常。。。
代码示例来源:origin: apache/nifi
public static long copyBytes(final byte[] bytes, final File destination, final boolean lockOutputFile) throws FileNotFoundException, IOException {
FileOutputStream fos = null;
FileLock outLock = null;
long fileSize = 0L;
try {
fos = new FileOutputStream(destination);
final FileChannel out = fos.getChannel();
if (lockOutputFile) {
outLock = out.tryLock(0, Long.MAX_VALUE, false);
if (null == outLock) {
throw new IOException("Unable to obtain exclusive file lock for: " + destination.getAbsolutePath());
}
}
fos.write(bytes);
fos.flush();
fileSize = bytes.length;
} finally {
FileUtils.releaseQuietly(outLock);
FileUtils.closeQuietly(fos);
}
return fileSize;
}
代码示例来源:origin: apache/nifi
public static long copyFile(final File source, final OutputStream stream, final boolean closeOutputStream, final boolean lockInputFile) throws FileNotFoundException, IOException {
FileInputStream fis = null;
FileLock inLock = null;
long fileSize = 0L;
try {
fis = new FileInputStream(source);
final FileChannel in = fis.getChannel();
if (lockInputFile) {
inLock = in.tryLock(0, Long.MAX_VALUE, true);
if (inLock == null) {
throw new IOException("Unable to obtain exclusive file lock for: " + source.getAbsolutePath());
}
}
byte[] buffer = new byte[1 << 18]; //256 KB
int bytesRead = -1;
while ((bytesRead = fis.read(buffer)) != -1) {
stream.write(buffer, 0, bytesRead);
}
in.force(false);
stream.flush();
fileSize = in.size();
} finally {
FileUtils.releaseQuietly(inLock);
FileUtils.closeQuietly(fis);
if (closeOutputStream) {
FileUtils.closeQuietly(stream);
}
}
return fileSize;
}
代码示例来源:origin: apache/nifi
FileUtils.closeQuietly(fos);
代码示例来源:origin: apache/nifi
} while (bytesWritten < fileSize);
out.force(false);
FileUtils.closeQuietly(fos);
FileUtils.closeQuietly(fis);
fos = null;
fis = null;
FileUtils.releaseQuietly(inLock);
FileUtils.releaseQuietly(outLock);
FileUtils.closeQuietly(fos);
FileUtils.closeQuietly(fis);
代码示例来源:origin: apache/nifi
public SSLContextFactory(final NiFiProperties properties) throws NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, KeyStoreException, UnrecoverableKeyException {
keystore = properties.getProperty(NiFiProperties.SECURITY_KEYSTORE);
keystorePass = getPass(properties.getProperty(NiFiProperties.SECURITY_KEYSTORE_PASSWD));
keystoreType = properties.getProperty(NiFiProperties.SECURITY_KEYSTORE_TYPE);
truststore = properties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE);
truststorePass = getPass(properties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD));
truststoreType = properties.getProperty(NiFiProperties.SECURITY_TRUSTSTORE_TYPE);
// prepare the keystore
final KeyStore keyStore = KeyStoreUtils.getKeyStore(keystoreType);
final FileInputStream keyStoreStream = new FileInputStream(keystore);
try {
keyStore.load(keyStoreStream, keystorePass);
} finally {
FileUtils.closeQuietly(keyStoreStream);
}
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keystorePass);
// prepare the truststore
final KeyStore trustStore = KeyStoreUtils.getTrustStore(truststoreType);
final FileInputStream trustStoreStream = new FileInputStream(truststore);
try {
trustStore.load(trustStoreStream, truststorePass);
} finally {
FileUtils.closeQuietly(trustStoreStream);
}
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
keyManagers = keyManagerFactory.getKeyManagers();
trustManagers = trustManagerFactory.getTrustManagers();
}
代码示例来源:origin: apache/nifi
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Capture all the headers for reference. Intentionally choosing to not special handling for headers with multiple values for clarity
final Enumeration<String> headerNames = request.getHeaderNames();
lastPostHeaders = new HashMap<>();
while (headerNames.hasMoreElements()) {
final String nextHeader = headerNames.nextElement();
lastPostHeaders.put(nextHeader, request.getHeader(nextHeader));
}
try {
StreamUtils.copy(request.getInputStream(), baos);
this.lastPost = baos.toByteArray();
} finally {
FileUtils.closeQuietly(baos);
}
response.setStatus(Status.OK.getStatusCode());
}
代码示例来源:origin: org.apache.nifi/nifi-utils
public static long copyBytes(final byte[] bytes, final File destination, final boolean lockOutputFile) throws FileNotFoundException, IOException {
FileOutputStream fos = null;
FileLock outLock = null;
long fileSize = 0L;
try {
fos = new FileOutputStream(destination);
final FileChannel out = fos.getChannel();
if (lockOutputFile) {
outLock = out.tryLock(0, Long.MAX_VALUE, false);
if (null == outLock) {
throw new IOException("Unable to obtain exclusive file lock for: " + destination.getAbsolutePath());
}
}
fos.write(bytes);
fos.flush();
fileSize = bytes.length;
} finally {
FileUtils.releaseQuietly(outLock);
FileUtils.closeQuietly(fos);
}
return fileSize;
}
代码示例来源:origin: org.apache.nifi/nifi-utils
public static long copyFile(final File source, final OutputStream stream, final boolean closeOutputStream, final boolean lockInputFile) throws FileNotFoundException, IOException {
FileInputStream fis = null;
FileLock inLock = null;
long fileSize = 0L;
try {
fis = new FileInputStream(source);
final FileChannel in = fis.getChannel();
if (lockInputFile) {
inLock = in.tryLock(0, Long.MAX_VALUE, true);
if (inLock == null) {
throw new IOException("Unable to obtain exclusive file lock for: " + source.getAbsolutePath());
}
}
byte[] buffer = new byte[1 << 18]; //256 KB
int bytesRead = -1;
while ((bytesRead = fis.read(buffer)) != -1) {
stream.write(buffer, 0, bytesRead);
}
in.force(false);
stream.flush();
fileSize = in.size();
} finally {
FileUtils.releaseQuietly(inLock);
FileUtils.closeQuietly(fis);
if (closeOutputStream) {
FileUtils.closeQuietly(stream);
}
}
return fileSize;
}
代码示例来源:origin: org.apache.nifi/nifi-utils
FileUtils.closeQuietly(fos);
代码示例来源:origin: org.apache.nifi/nifi-utils
} while (bytesWritten < fileSize);
out.force(false);
FileUtils.closeQuietly(fos);
FileUtils.closeQuietly(fis);
fos = null;
fis = null;
FileUtils.releaseQuietly(inLock);
FileUtils.releaseQuietly(outLock);
FileUtils.closeQuietly(fos);
FileUtils.closeQuietly(fis);
内容来源于网络,如有侵权,请联系作者删除!