本文整理汇总了Java中java.io.BufferedOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedOutputStream.close方法的具体用法?Java BufferedOutputStream.close怎么用?Java BufferedOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.BufferedOutputStream
的用法示例。
在下文中一共展示了BufferedOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fileCombination
import java.io.BufferedOutputStream; //导入方法依赖的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: createBlobFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private void createBlobFile(int size) throws Exception {
if (testBlobFile != null && testBlobFile.length() != size) {
testBlobFile.delete();
}
testBlobFile = File.createTempFile(TEST_BLOB_FILE_PREFIX, ".dat");
testBlobFile.deleteOnExit();
// TODO: following cleanup doesn't work correctly during concurrent execution of testsuite
// cleanupTempFiles(testBlobFile, TEST_BLOB_FILE_PREFIX);
BufferedOutputStream bOut = new BufferedOutputStream(new FileOutputStream(testBlobFile));
int dataRange = Byte.MAX_VALUE - Byte.MIN_VALUE;
for (int i = 0; i < size; i++) {
bOut.write((byte) ((Math.random() * dataRange) + Byte.MIN_VALUE));
}
bOut.flush();
bOut.close();
}
示例3: newTempBinaryFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
protected File newTempBinaryFile(String name, long size) throws IOException {
File tempFile = File.createTempFile(name, "tmp");
tempFile.deleteOnExit();
cleanupTempFiles(tempFile, name);
FileOutputStream fos = new FileOutputStream(tempFile);
BufferedOutputStream bos = new BufferedOutputStream(fos);
for (long i = 0; i < size; i++) {
bos.write((byte) i);
}
bos.close();
assertTrue(tempFile.exists());
assertEquals(size, tempFile.length());
return tempFile;
}
示例4: saveBitmapToLocal
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
* save image from uri
* @param outPath
* @param bitmap
* @return
*/
public static String saveBitmapToLocal(String outPath , Bitmap bitmap) {
try {
String imagePath = outPath + HelpUtils.md5(DateFormat.format("yyyy-MM-dd-HH-mm-ss", System.currentTimeMillis()).toString()) + ".jpg";
File file = new File(imagePath);
if(!file.exists()) {
file.createNewFile();
}
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bufferedOutputStream);
bufferedOutputStream.close();
LogUtil.d(TAG, "photo image from data, path:" + imagePath);
return imagePath;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例5: saveImageToSD
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
* 写图片文件到SD卡
*
* @throws IOException
*/
public static void saveImageToSD(Context ctx, String filePath,
Bitmap bitmap, int quality) throws IOException {
if (bitmap != null) {
File file = new File(filePath.substring(0,
filePath.lastIndexOf(File.separator)));
if (!file.exists()) {
file.mkdirs();
}
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(filePath));
bitmap.compress(CompressFormat.PNG, quality, bos);
bos.flush();
bos.close();
if (ctx != null) {
scanPhoto(ctx, filePath);
}
}
}
示例6: saveBinaryFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static State saveBinaryFile(byte[] data, String path) {
File file = new File(path);
State state = valid(file);
if (!state.isSuccess()) {
return state;
}
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bos.write(data);
bos.flush();
bos.close();
} catch (IOException ioe) {
return new BaseState(false, AppInfo.IO_ERROR);
}
state = new BaseState(true, file.getAbsolutePath());
state.putInfo("size", data.length);
state.putInfo("title", file.getName());
return state;
}
示例7: downloadUrlToStream
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
* Download a bitmap from a URL and write the content to an output stream.
*
* @param urlString The URL to fetch
* @return true if successful, false otherwise
*/
private boolean downloadUrlToStream(String urlString, OutputStream outputStream) throws IOException{
final URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
BufferedInputStream in = new BufferedInputStream(urlConnection.getInputStream(), IO_BUFFER_SIZE);
BufferedOutputStream out = new BufferedOutputStream(outputStream, IO_BUFFER_SIZE);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
urlConnection.disconnect();
try {
out.close();
in.close();
} catch (final IOException e) {e.printStackTrace();}
return true;
}
示例8: write
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
@Override
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
Objects.requireNonNull(stream);
Objects.requireNonNull(fileType);
Objects.requireNonNull(out);
// throws IllegalArgumentException if not supported
WaveFileFormat waveFileFormat = (WaveFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeWaveFile(stream, waveFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( waveFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
int dataLength=bytesWritten-waveFileFormat.getHeaderSize();
int riffLength=dataLength + waveFileFormat.getHeaderSize() - 8;
RandomAccessFile raf=new RandomAccessFile(out, "rw");
// skip RIFF magic
raf.skipBytes(4);
raf.writeInt(big2little( riffLength ));
// skip WAVE magic, fmt_ magic, fmt_ length, fmt_ chunk, data magic
raf.skipBytes(4+4+4+WaveFileFormat.getFmtChunkSize(waveFileFormat.getWaveType())+4);
raf.writeInt(big2little( dataLength ));
// that's all
raf.close();
}
return bytesWritten;
}
示例9: saveProperties
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
protected void saveProperties(Properties properties, FileObject storage) throws IOException {
synchronized (this) {
OutputStream os = storage.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
try {
properties.storeToXML(bos, ""); // NOI18N
} finally {
if (bos != null) bos.close();
}
}
}
示例10: write
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public int write(AudioInputStream stream, AudioFileFormat.Type fileType, File out) throws IOException {
// throws IllegalArgumentException if not supported
AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);
// first write the file without worrying about length fields
FileOutputStream fos = new FileOutputStream( out ); // throws IOException
BufferedOutputStream bos = new BufferedOutputStream( fos, bisBufferSize );
int bytesWritten = writeAuFile(stream, auFileFormat, bos );
bos.close();
// now, if length fields were not specified, calculate them,
// open as a random access file, write the appropriate fields,
// close again....
if( auFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {
// $$kk: 10.22.99: jan: please either implement this or throw an exception!
// $$fb: 2001-07-13: done. Fixes Bug 4479981
RandomAccessFile raf=new RandomAccessFile(out, "rw");
if (raf.length()<=0x7FFFFFFFl) {
// skip AU magic and data offset field
raf.skipBytes(8);
raf.writeInt(bytesWritten-AuFileFormat.AU_HEADERSIZE);
// that's all
}
raf.close();
}
return bytesWritten;
}
示例11: saveFileByInputStream
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static State saveFileByInputStream(InputStream is, String path, long maxSize) {
State state = null;
File tmpFile = getTmpFile();
byte[] dataBuf = new byte[2048];
BufferedInputStream bis = new BufferedInputStream(is, StorageManager.BUFFER_SIZE);
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpFile), StorageManager.BUFFER_SIZE);
int count = 0;
while ((count = bis.read(dataBuf)) != -1) {
bos.write(dataBuf, 0, count);
}
bos.flush();
bos.close();
if (tmpFile.length() > maxSize) {
tmpFile.delete();
return new BaseState(false, AppInfo.MAX_SIZE);
}
state = saveTmpFile(tmpFile, path);
if (!state.isSuccess()) {
tmpFile.delete();
}
return state;
} catch (IOException e) {
}
return new BaseState(false, AppInfo.IO_ERROR);
}
示例12: extractFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
byte[] bytesIn = new byte[BUFFER_SIZE];
int read = 0;
while ((read = zipIn.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
示例13: testPutFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
@Test
public void testPutFile() throws IOException {
if (!judgeUserInfoValid()) {
return;
}
String key = "ut/generate_url_test_upload.txt";
File localFile = buildTestFile(1024);
Date expirationTime = new Date(System.currentTimeMillis() + 30 * 60 * 1000);
URL url = cosclient.generatePresignedUrl(bucket, key, expirationTime, HttpMethodName.PUT);
System.out.println(url.toString());
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
BufferedOutputStream bos = new BufferedOutputStream(connection.getOutputStream());
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(localFile));
int readByte = -1;
while ((readByte = bis.read()) != -1) {
bos.write(readByte);
}
bis.close();
bos.close();
int responseCode = connection.getResponseCode();
assertEquals(200, responseCode);
headSimpleObject(key, localFile.length(), Md5Utils.md5Hex(localFile));
clearObject(key);
localFile.delete();
}
示例14: postFileUpload
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
@Override
public void postFileUpload(final String uploadServletUrl,
final String fileName, final byte[] bytes) throws IOException {
File file = null;
try {
client = new DefaultHttpClient();
client.getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
// if uploadServletURL is malformed - exception is thrown
new URL(uploadServletUrl);
file = File.createTempFile(fileName, "");
final BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(file));
bos.write(bytes);
bos.flush();
bos.close();
final HttpPost post = new HttpPost(uploadServletUrl);
final MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
entity.addPart("file", new FileBody(file,
"application/octet-stream"));
post.setEntity(entity);
client.execute(post);
} catch (final IOException e) {
throw e;
} finally {
client.getConnectionManager().shutdown();
if (file != null && file.exists()) {
file.delete();
}
}
}
示例15: writeToFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static void writeToFile(InputStream dataIns, File target) throws IOException {
final int BUFFER = 1024;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
int count;
byte data[] = new byte[BUFFER];
while ((count = dataIns.read(data, 0, BUFFER)) != -1) {
bos.write(data, 0, count);
}
bos.close();
}