本文整理了Java中java.io.BufferedInputStream.close()
方法的一些代码示例,展示了BufferedInputStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedInputStream.close()
方法的具体详情如下:
包路径:java.io.BufferedInputStream
类名称:BufferedInputStream
方法名:close
[英]Closes this input stream and releases any system resources associated with the stream. Once the stream has been closed, further read(), available(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.
[中]关闭此输入流并释放与该流关联的所有系统资源。关闭流后,进一步的read()、available()、reset()或skip()调用将抛出IOException。关闭以前关闭的流没有效果。
代码示例来源:origin: log4j/log4j
/**
* Loads a log file from a web server into the LogFactor5 GUI.
*/
private String loadLogFile(InputStream stream) throws IOException {
BufferedInputStream br = new BufferedInputStream(stream);
int count = 0;
int size = br.available();
StringBuffer sb = null;
if (size > 0) {
sb = new StringBuffer(size);
} else {
sb = new StringBuffer(1024);
}
while ((count = br.read()) != -1) {
sb.append((char) count);
}
br.close();
br = null;
return sb.toString();
}
代码示例来源:origin: stackoverflow.com
BufferedInputStream bis = new BufferedInputStream(entity.getContent());
String filePath = "sample.txt";
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
int inByte;
while((inByte = bis.read()) != -1) bos.write(inByte);
bis.close();
bos.close();
代码示例来源:origin: alibaba/mdrill
private void transToBAOS(BufferedInputStream bi,
ByteArrayOutputStream bos) throws Exception {
while (true) {
synchronized (m_buffer) {
int amountRead = bi.read(m_buffer);
if (amountRead == -1) {
break;
}
bos.write(m_buffer, 0, amountRead);
}
}
bi.close();
}
代码示例来源:origin: commons-codec/commons-codec
/**
* Returns the digest for the file.
*
* @param valueToDigest the file to use
* @return the digest
* @throws IOException
* If an I/O error occurs.
* @since 1.11
*/
public byte[] hmac(final File valueToDigest) throws IOException {
final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(valueToDigest));
try {
return hmac(stream);
} finally {
stream.close();
}
}
代码示例来源:origin: Rajawali/Rajawali
/**
* Determine the content generator (i.e. Slic3r, Skeinforge) for the given resource.
*
* @param res
* @param resId
* @return
* @throws IOException
*/
public static final GCodeFlavor tasteFlavor(Resources res, int resId) throws IOException, NotFoundException {
BufferedInputStream buffer = new BufferedInputStream(res.openRawResource(resId));
GCodeFlavor ret = tasteFlavor(buffer);
buffer.close();
return ret;
}
代码示例来源:origin: stackoverflow.com
File file = new File(path);
int size = (int) file.length();
byte[] bytes = new byte[size];
try {
BufferedInputStream buf = new BufferedInputStream(new FileInputStream(file));
buf.read(bytes, 0, bytes.length);
buf.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
代码示例来源:origin: commons-codec/commons-codec
/**
* Reads through a File and updates the digest for the data
*
* @param digest
* The MessageDigest to use (e.g. MD5)
* @param data
* Data to digest
* @return the digest
* @throws IOException
* On error reading from the stream
* @since 1.11
*/
public static MessageDigest updateDigest(final MessageDigest digest, final File data) throws IOException {
final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(data));
try {
return updateDigest(digest, stream);
} finally {
stream.close();
}
}
代码示例来源:origin: aws/aws-sdk-java
private static byte[] computeSHA256Hash(byte[] data) throws NoSuchAlgorithmException, IOException {
BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(data));
try {
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
byte[] buffer = new byte[16384];
int bytesRead = -1;
while ( (bytesRead = bis.read(buffer, 0, buffer.length)) != -1 ) {
messageDigest.update(buffer, 0, bytesRead);
}
return messageDigest.digest();
} finally {
try { bis.close(); } catch ( Exception e ) {}
}
}
}
代码示例来源:origin: iBotPeaches/Apktool
private ResPackage[] getResPackagesFromApk(ExtFile apkFile,ResTable resTable, boolean keepBroken)
throws AndrolibException {
try {
Directory dir = apkFile.getDirectory();
BufferedInputStream bfi = new BufferedInputStream(dir.getFileInput("resources.arsc"));
try {
return ARSCDecoder.decode(bfi, false, keepBroken, resTable).getPackages();
} finally {
try {
bfi.close();
} catch (IOException ignored) {}
}
} catch (DirectoryException ex) {
throw new AndrolibException("Could not load resources.arsc from file: " + apkFile, ex);
}
}
代码示例来源:origin: ankidroid/Anki-Android
private void writeEntry(BufferedInputStream bis, ZipEntry ze) throws IOException {
byte[] buf = new byte[BUFFER_SIZE];
mZos.putNextEntry(ze);
int len;
while ((len = bis.read(buf, 0, BUFFER_SIZE)) != -1) {
mZos.write(buf, 0, len);
}
mZos.closeEntry();
bis.close();
}
代码示例来源:origin: apache/geode
private byte[] fileDigest(File file) throws IOException {
BufferedInputStream fis = new BufferedInputStream(new FileInputStream(file));
try {
byte[] data = new byte[8192];
int read;
while ((read = fis.read(data)) > 0) {
messageDigest.update(data, 0, read);
}
} finally {
fis.close();
}
return messageDigest.digest();
}
代码示例来源:origin: azkaban/azkaban
public static byte[] md5Hash(final File file) throws IOException {
final MessageDigest digest = getMd5Digest();
final FileInputStream fStream = new FileInputStream(file);
final BufferedInputStream bStream = new BufferedInputStream(fStream);
final DigestInputStream blobStream = new DigestInputStream(bStream, digest);
final byte[] buffer = new byte[BYTE_BUFFER_SIZE];
int num = 0;
do {
num = blobStream.read(buffer);
} while (num > 0);
bStream.close();
return digest.digest();
}
代码示例来源:origin: facebook/facebook-android-sdk
public static int copyAndCloseInputStream(InputStream inputStream, OutputStream outputStream)
throws IOException {
BufferedInputStream bufferedInputStream = null;
int totalBytes = 0;
try {
bufferedInputStream = new BufferedInputStream(inputStream);
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytes += bytesRead;
}
} finally {
if (bufferedInputStream != null) {
bufferedInputStream.close();
}
if (inputStream != null) {
inputStream.close();
}
}
return totalBytes;
}
代码示例来源:origin: mttkay/ignition
@Override
protected byte[] readValueFromDisk(File file) throws IOException {
BufferedInputStream istream = new BufferedInputStream(new FileInputStream(file));
long fileSize = file.length();
if (fileSize > Integer.MAX_VALUE) {
throw new IOException("Cannot read files larger than " + Integer.MAX_VALUE + " bytes");
}
int imageDataLength = (int) fileSize;
byte[] imageData = new byte[imageDataLength];
istream.read(imageData, 0, imageDataLength);
istream.close();
return imageData;
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Loads a classifier from the file specified. If the file's name ends in .gz,
* uses a GZIPInputStream, else uses a regular FileInputStream. This method
* closes the File when done.
*
* @param file Loads a classifier from this file.
* @param props Properties in this object will be used to overwrite those
* specified in the serialized classifier
*
* @throws IOException If there are problems accessing the input stream
* @throws ClassCastException If there are problems interpreting the serialized data
* @throws ClassNotFoundException If there are problems interpreting the serialized data
*/
public void loadClassifier(File file, Properties props) throws ClassCastException, IOException,
ClassNotFoundException {
Timing t = new Timing();
BufferedInputStream bis;
if (file.getName().endsWith(".gz")) {
bis = new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)));
} else {
bis = new BufferedInputStream(new FileInputStream(file));
}
try {
loadClassifier(bis, props);
t.done(log, "Loading classifier from " + file.getAbsolutePath());
} finally {
bis.close();
}
}
代码示例来源:origin: spring-projects/spring-loaded
public static byte[] loadBytesFromStream(InputStream stream) {
try {
BufferedInputStream bis = new BufferedInputStream(stream);
byte[] theData = new byte[10000000];
int dataReadSoFar = 0;
byte[] buffer = new byte[1024];
int read = 0;
while ((read = bis.read(buffer)) != -1) {
System.arraycopy(buffer, 0, theData, dataReadSoFar, read);
dataReadSoFar += read;
}
bis.close();
// Resize to actual data read
byte[] returnData = new byte[dataReadSoFar];
System.arraycopy(theData, 0, returnData, 0, dataReadSoFar);
return returnData;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: stackoverflow.com
public void saveUrl(final String filename, final String urlString)
throws MalformedURLException, IOException {
BufferedInputStream in = null;
FileOutputStream fout = null;
try {
in = new BufferedInputStream(new URL(urlString).openStream());
fout = new FileOutputStream(filename);
final byte data[] = new byte[1024];
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
} finally {
if (in != null) {
in.close();
}
if (fout != null) {
fout.close();
}
}
}
代码示例来源:origin: iBotPeaches/Apktool
zipEntry.setMethod(ZipEntry.STORED);
zipEntry.setSize(file.length());
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file));
CRC32 crc = BrutIO.calculateCrc(unknownFile);
zipEntry.setCrc(crc.getValue());
unknownFile.close();
} else {
zipEntry.setMethod(ZipEntry.DEFLATED);
try (FileInputStream inputStream = new FileInputStream(file)) {
IOUtils.copy(inputStream, zipOutputStream);
代码示例来源:origin: spring-projects/spring-loaded
public static byte[] loadBytesFromStream(InputStream stream) {
try {
BufferedInputStream bis = new BufferedInputStream(stream);
byte[] theData = new byte[10000000];
int dataReadSoFar = 0;
byte[] buffer = new byte[1024];
int read = 0;
while ((read = bis.read(buffer)) != -1) {
System.arraycopy(buffer, 0, theData, dataReadSoFar, read);
dataReadSoFar += read;
}
bis.close();
// Resize to actual data read
byte[] returnData = new byte[dataReadSoFar];
System.arraycopy(theData, 0, returnData, 0, dataReadSoFar);
return returnData;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: igniterealtime/Smack
private static byte[] getFileBytes(File file) throws IOException {
BufferedInputStream bis = null;
try {
bis = new BufferedInputStream(new FileInputStream(file));
int bytes = (int) file.length();
byte[] buffer = new byte[bytes];
int readBytes = bis.read(buffer);
if (readBytes != buffer.length) {
throw new IOException("Entire file not read");
}
return buffer;
}
finally {
if (bis != null) {
bis.close();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!