本文整理汇总了Java中java.io.BufferedInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedInputStream.close方法的具体用法?Java BufferedInputStream.close怎么用?Java BufferedInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.BufferedInputStream
的用法示例。
在下文中一共展示了BufferedInputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fileCombination
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public static void fileCombination(File file, String targetFile) throws Exception {
outFile = new File(targetFile);
output = new BufferedOutputStream(new FileOutputStream(outFile),128*1024);
childReader = new BufferedReader(new FileReader(file));
String name;
while ((name = childReader.readLine()) != null) {
cFile = new File(name);
fileReader = new BufferedInputStream(new FileInputStream(cFile),128*1024);
int content;
while ((content = fileReader.read()) != -1) {
output.write(content);
}
output.flush();
}
output.close();
fileReader.close();
childReader.close();
}
示例2: createBinaryFilePositiveWithUidAndGidOnWindows
import java.io.BufferedInputStream; //导入方法依赖的package包/类
@Test
public void createBinaryFilePositiveWithUidAndGidOnWindows() throws Exception {
expect(OperatingSystemType.getCurrentOsType()).andReturn(OperatingSystemType.WINDOWS);
replayAll();
testObject.createBinaryFile(file.getPath(), 18, 120, 230, false);
// verify results
verifyAll();
assertTrue(file.exists());
assertEquals(18L, file.length());
byte[] actualBytes = new byte[18];
byte[] expectedBytes = new byte[18];
byte nextByte = Byte.MIN_VALUE;
for (int i = 0; i < expectedBytes.length; i++) {
expectedBytes[i] = nextByte++;
}
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
bis.read(actualBytes);
assertTrue(Arrays.equals(expectedBytes, actualBytes));
bis.close();
}
示例3: finalizeCnf
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void finalizeCnf() {
try {
free();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(cnfFile));
File tmp = new File(cnfFile + ".tmp");
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmp));
byte[] header = String.format("p cnf %s %s\n", vars, clauses).getBytes();
out.write(header);
int ch;
while ((ch = in.read()) != -1) {
out.write(ch);
}
in.close();
out.close();
tmp.renameTo(cnfFile);
} catch (IOException e) {
throw new RuntimeException("could not preprend header to cnf file: " + cnfFile.getAbsolutePath(), e);
}
}
示例4: main
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
File file = new File(System.getProperty("test.src", "."), "ding.sf2");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
try
{
InputStream badis = new BadInputStream(bis);
Soundbank sf2 = new SF2SoundbankReader().getSoundbank(badis);
assertTrue(sf2.getInstruments().length == 1);
Patch patch = sf2.getInstruments()[0].getPatch();
assertTrue(patch.getProgram() == 0);
assertTrue(patch.getBank() == 0);
}
finally
{
bis.close();
}
}
示例5: writeFile
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* 文件回写
* @param path
* @param session
* @throws IOException
*/
public static void writeFile(String path, IoSession out) throws IOException{
File file = new File(path);
if(file.exists() && !file.isDirectory()){
out.write((
"HTTP/1.1 200 OK" +
"\r\n" +
"Content-Type: text/html" +
"\r\n" +
"Content-Length: " + file.length() +
"\r\n" +
"\r\n").getBytes());
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
while(true){
int data = in.read();
if(data == -1) break;
out.write(data);
}
in.close();
}else{
String ct = "400 - NOT FIND! \r\n PATH : " + path;
out.write((
"HTTP/1.1 400 NOT FIND" +
"\r\n" +
"Content-Type: text/html" +
"\r\n" +
"Content-Length: " + ct.getBytes("iso-8859-1") +
"\r\n" +
"\r\n").getBytes());
out.write(ct.getBytes());
}
}
示例6: writeByFile
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public void writeByFile(File file) throws IOException {
mark = file.getName();
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] buf = new byte[1024];
int len;
while ((len = bis.read(buf)) > 0) {
write(buf, 0, len);
}
fis.close();
bis.close();
}
示例7: getMidiFileFormat
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public MidiFileFormat getMidiFileFormat(URL url) throws InvalidMidiDataException, IOException {
InputStream urlStream = url.openStream(); // throws IOException
BufferedInputStream bis = new BufferedInputStream( urlStream, bisBufferSize );
MidiFileFormat fileFormat = null;
try {
fileFormat = getMidiFileFormat( bis ); // throws InvalidMidiDataException
} finally {
bis.close();
}
return fileFormat;
}
示例8: testGetResourceWithTCCL
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Verifies that <tt>getResource</tt> works with TCCL from {@link ClassPathLoader}.
*/
@Test
public void testGetResourceWithTCCL() throws Exception {
System.out.println("\nStarting ClassPathLoaderTest#testGetResourceWithTCCL");
ClassPathLoader dcl = ClassPathLoader.createWithDefaults(false);
String resourceToGet = "com/nowhere/testGetResourceWithTCCL.rsc";
assertNull(dcl.getResource(resourceToGet));
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(new GeneratingClassLoader());
URL url = dcl.getResource(resourceToGet);
assertNotNull(url);
InputStream is = url.openStream();
assertNotNull(is);
int totalBytesRead = 0;
byte[] input = new byte[128];
BufferedInputStream bis = new BufferedInputStream(is);
for (int bytesRead = bis.read(input); bytesRead > -1;) {
totalBytesRead += bytesRead;
bytesRead = bis.read(input);
}
bis.close();
assertEquals(TEMP_FILE_BYTES_COUNT, totalBytesRead);
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
示例9: StringPrep
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Creates an StringPrep object after reading the input stream.
* The object does not hold a reference to the input steam, so the stream can be
* closed after the method returns.
*
* @param inputStream The stream for reading the StringPrep profile binarySun
* @throws IOException
* @draft ICU 2.8
*/
public StringPrep(InputStream inputStream) throws IOException{
BufferedInputStream b = new BufferedInputStream(inputStream,DATA_BUFFER_SIZE);
StringPrepDataReader reader = new StringPrepDataReader(b);
// read the indexes
indexes = reader.readIndexes(INDEX_TOP);
byte[] sprepBytes = new byte[indexes[INDEX_TRIE_SIZE]];
//indexes[INDEX_MAPPING_DATA_SIZE] store the size of mappingData in bytes
mappingData = new char[indexes[INDEX_MAPPING_DATA_SIZE]/2];
// load the rest of the data data and initialize the data members
reader.read(sprepBytes,mappingData);
sprepTrieImpl = new StringPrepTrieImpl();
sprepTrieImpl.sprepTrie = new CharTrie( new ByteArrayInputStream(sprepBytes),sprepTrieImpl );
// get the data format version
formatVersion = reader.getDataFormatVersion();
// get the options
doNFKC = ((indexes[OPTIONS] & NORMALIZATION_ON) > 0);
checkBiDi = ((indexes[OPTIONS] & CHECK_BIDI_ON) > 0);
sprepUniVer = getVersionInfo(reader.getUnicodeVersion());
normCorrVer = getVersionInfo(indexes[NORM_CORRECTNS_LAST_UNI_VERSION]);
VersionInfo normUniVer = NormalizerImpl.getUnicodeVersion();
if(normUniVer.compareTo(sprepUniVer) < 0 && /* the Unicode version of SPREP file must be less than the Unicode Vesion of the normalization data */
normUniVer.compareTo(normCorrVer) < 0 && /* the Unicode version of the NormalizationCorrections.txt file should be less than the Unicode Vesion of the normalization data */
((indexes[OPTIONS] & NORMALIZATION_ON) > 0) /* normalization turned on*/
){
throw new IOException("Normalization Correction version not supported");
}
b.close();
}
示例10: UCharacterProperty
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Constructor
* @exception IOException thrown when data reading fails or data corrupted
*/
private UCharacterProperty() throws IOException
{
// jar access
InputStream is = ICUData.getRequiredStream(DATA_FILE_NAME_);
BufferedInputStream b = new BufferedInputStream(is, DATA_BUFFER_SIZE_);
UCharacterPropertyReader reader = new UCharacterPropertyReader(b);
reader.read(this);
b.close();
m_trie_.putIndexData(this);
}
示例11: checkBlob
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private boolean checkBlob(byte[] retrBytes) throws Exception {
boolean passed = false;
BufferedInputStream bIn = new BufferedInputStream(new FileInputStream(testBlobFile));
try {
int fileLength = (int) testBlobFile.length();
if (retrBytes.length == fileLength) {
for (int i = 0; i < fileLength; i++) {
byte fromFile = (byte) (bIn.read() & 0xff);
if (retrBytes[i] != fromFile) {
passed = false;
System.out.println("Byte pattern differed at position " + i + " , " + retrBytes[i] + " != " + fromFile);
for (int j = 0; (j < (i + 10)) /* && (j < i) */; j++) {
System.out.print(Integer.toHexString(retrBytes[j] & 0xff) + " ");
}
break;
}
passed = true;
}
} else {
passed = false;
System.out.println("retrBytes.length(" + retrBytes.length + ") != testBlob.length(" + fileLength + ")");
}
return passed;
} finally {
if (bIn != null) {
bIn.close();
}
}
}
示例12: dumpAsset
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* 保存文件
* This method checks if the given file exists on disk. If it does it's ignored because
* that means that the file is allready cached on the server. If not we take out the stream from the
* digitalAsset-object and dumps it.
*/
public void dumpAsset(File file, String fileName, String filePath) throws Exception
{
long timer = System.currentTimeMillis();
File outputFile = new File(filePath + separator + fileName);
if(outputFile.exists())
{
log.info("The file allready exists so we don't need to dump it again..");
return;
}
FileOutputStream fis = new FileOutputStream(outputFile);
BufferedOutputStream bos = new BufferedOutputStream(fis);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
int character;
while ((character = bis.read()) != -1)
{
bos.write(character);
}
bos.flush();
bis.close();
fis.close();
bos.close();
log.info("Time for dumping file " + fileName + ":" + (System.currentTimeMillis() - timer));
}
示例13: testGetResources
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Verifies that {@link ClassPathLoader#getLatest()} can actually <tt>getResources</tt> when it
* exists.
*/
@Test
public void testGetResources() throws Exception {
System.out.println("\nStarting ClassPathLoaderTest#testGetResources");
String resourceToGet = "org/apache/geode/internal/classpathloaderjunittest/DoesExist.class";
Enumeration<URL> urls = ClassPathLoader.getLatest().getResources(resourceToGet);
assertNotNull(urls);
assertTrue(urls.hasMoreElements());
URL url = urls.nextElement();
InputStream is = url != null ? url.openStream() : null;
assertNotNull(is);
int totalBytesRead = 0;
byte[] input = new byte[256];
BufferedInputStream bis = new BufferedInputStream(is);
for (int bytesRead = bis.read(input); bytesRead > -1;) {
totalBytesRead += bytesRead;
bytesRead = bis.read(input);
}
bis.close();
// if the following fails then maybe javac changed and DoesExist.class
// contains other than 374 bytes of data... consider updating this test
assertEquals(GENERATED_CLASS_BYTES_COUNT, totalBytesRead);
}
示例14: call0
import java.io.BufferedInputStream; //导入方法依赖的package包/类
@Override
protected Void call0() throws Exception {
updateProgress(0, 1);
String url0 = crawl(crawlAddHost("http://minecraft.curseforge.com/projects/" + fileJson.projectID) + "/files/" + fileJson.fileID + "/download");
if (DownloadModsTask.this.isCancelled()) return null;
URL url = new URL(url0);
String fileName = new File(url.getFile()).getName().replaceAll("%20", " ");
log("> Downloading " + fileName);
Platform.runLater(() -> getController().setSecondaryProgress(this, fileName));
HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
long completeFileSize = httpConnection.getContentLength();
BufferedInputStream bis = new BufferedInputStream(httpConnection.getInputStream());
File file = new File(CMPDL.getModsDirectory() + File.separator + fileName);
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
byte[] buffer = new byte[1024];
long dl = 0;
int count;
while ((count = bis.read(buffer, 0, 1024)) != -1 && !isCancelled()) {
fos.write(buffer, 0, count);
dl += count;
this.updateProgress(dl, completeFileSize);
}
fos.close();
bis.close();
log("> Download succeeded !");
return null;
}
示例15: upload
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public static String upload(File file) throws IOException {
String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=" + WeiXinCompanyUtils.getToken()
+ "&type=file";
// 定义数据分隔符
String boundary = "------------7da2e536604c8";
URL uploadUrl = new URL(urlStr);
HttpsURLConnection uploadConn = (HttpsURLConnection) uploadUrl.openConnection();
uploadConn.setDoOutput(true);
uploadConn.setDoInput(true);
uploadConn.setRequestMethod("POST");
// 设置请求头Content-Type
uploadConn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
// 获取媒体文件上传的输出流(往微信服务器写数据)
OutputStream outputStream = uploadConn.getOutputStream();
// 从请求头中获取内容类型
String contentType = "text";
// 根据内容类型判断文件扩展名
String ext = file.getName().substring(file.getName().lastIndexOf("."));
String name = file.getName();
// 请求体开始
outputStream.write(("--" + boundary + "\r\n").getBytes());
String aaa = String
.format("Content-Disposition: form-data; name=\"media\"; filename=\"" + name + "." + "%s\"\r\n", ext);
outputStream.write(aaa.getBytes());
String bbb = String.format("Content-Type: %s\r\n\r\n", contentType);
outputStream.write(bbb.getBytes());
// 获取媒体文件的输入流(读取文件)
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buf = new byte[8096];
int size = 0;
while ((size = bis.read(buf)) != -1) {
// 将媒体文件写到输出流(往微信服务器写数据)
outputStream.write(buf, 0, size);
}
// 请求体结束
outputStream.write(("\r\n--" + boundary + "--\r\n").getBytes());
outputStream.close();
bis.close();
// 获取媒体文件上传的输入流(从微信服务器读数据)
InputStream inputStream = uploadConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuffer buffer = new StringBuffer();
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
// 释放资源
inputStream.close();
uploadConn.disconnect();
System.out.println(buffer.toString());
return buffer.toString();
}