本文整理汇总了Java中java.io.BufferedOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedOutputStream.write方法的具体用法?Java BufferedOutputStream.write怎么用?Java BufferedOutputStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.BufferedOutputStream
的用法示例。
在下文中一共展示了BufferedOutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
* 复制文件
*
* @param sourceFile
* @param targetFile
* @throws IOException
*/
public static void copyFile(File sourceFile, File targetFile) throws IOException {
// 新建文件输入流并对它进行缓冲
FileInputStream input = new FileInputStream(sourceFile);
BufferedInputStream inBuff = new BufferedInputStream(input);
// 新建文件输出流并对它进行缓冲
FileOutputStream output = new FileOutputStream(targetFile);
BufferedOutputStream outBuff = new BufferedOutputStream(output);
// 缓冲数组
byte[] b = new byte[1024 * 5];
int len;
while ((len = inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
// 刷新此缓冲的输出流
outBuff.flush();
// 关闭流
inBuff.close();
outBuff.close();
output.close();
input.close();
}
示例2: saveResponseContent
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private static String saveResponseContent(HttpURLConnection connection,
String responseFileName, String responseType) throws IOException {
File file = createFile(responseFileName, responseType);
BufferedInputStream in = new BufferedInputStream(getConnectionStream(connection), 0x1000);
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file), 0x1000);
try {
// Copy the contents from the input stream to the output stream.
while (true) {
int b = in.read();
if (b == -1) {
break;
}
out.write(b);
}
out.flush();
} finally {
out.close();
}
} finally {
in.close();
}
return file.getAbsolutePath();
}
示例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: copyFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static void copyFile(File sourceFile, File targetFile)
throws IOException {
// 新建文件输入流并对它进行缓冲
FileInputStream input = new FileInputStream(sourceFile);
BufferedInputStream inBuff = new BufferedInputStream(input);
// 新建文件输出流并对它进行缓冲
FileOutputStream output = new FileOutputStream(targetFile);
BufferedOutputStream outBuff = new BufferedOutputStream(output);
// 缓冲数组
byte[] b = new byte[1024 * 5];
int len;
while ((len = inBuff.read(b)) != -1) {
outBuff.write(b, 0, len);
}
// 刷新此缓冲的输出流
outBuff.flush();
//关闭流
inBuff.close();
outBuff.close();
output.close();
input.close();
}
示例5: testEmptyFinalColumn
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
@Test
public void testEmptyFinalColumn() throws Exception {
String dfs_temp = getDfsTestTmpSchemaLocation();
File table_dir = new File(dfs_temp, "emptyFinalColumn");
table_dir.mkdir();
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File(table_dir, "a.csvh")));
os.write("field1,field2\n".getBytes());
for (int i = 0; i < 10000; i++) {
os.write("a,\n".getBytes());
}
os.flush();
os.close();
String query = "select * from dfs_test.emptyFinalColumn";
TestBuilder builder = testBuilder()
.sqlQuery(query)
.ordered()
.baselineColumns("field1", "field2");
for (int i = 0; i < 10000; i++) {
builder.baselineValues("a", "");
}
builder.go();
}
示例6: writeCurrentOptions
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private void writeCurrentOptions( String fileName ) {
try {
String curOptions = fp.getCurrentOptions();
BufferedOutputStream bos =
new BufferedOutputStream( new FileOutputStream( fileName ));
/// Prepend title and the option that is only obtainable here
int range[] = rm.getSelectedRange();
String completeOptions =
( "Font2DTest Option File\n" +
displayGridCBMI.getState() + "\n" +
force16ColsCBMI.getState() + "\n" +
showFontInfoCBMI.getState() + "\n" +
rm.getSelectedItem() + "\n" +
range[0] + "\n" + range[1] + "\n" + curOptions + tFileName);
byte toBeWritten[] = completeOptions.getBytes( "UTF-16" );
bos.write( toBeWritten, 0, toBeWritten.length );
bos.close();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Save Options File; See Stack Trace", true );
ex.printStackTrace();
}
}
示例7: sendParams
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
* Send parameters to output stream of request
*
* @param request
* @param params
* @throws IOException
*/
protected void sendParams(HttpURLConnection request, Object params)
throws IOException {
request.setDoOutput(true);
if (params != null) {
request.setRequestProperty(HEADER_CONTENT_TYPE, CONTENT_TYPE_JSON
+ "; charset=" + CHARSET_UTF8); //$NON-NLS-1$
byte[] data = toJson(params).getBytes(CHARSET_UTF8);
request.setFixedLengthStreamingMode(data.length);
BufferedOutputStream output = new BufferedOutputStream(
request.getOutputStream(), bufferSize);
try {
output.write(data);
output.flush();
} finally {
try {
output.close();
} catch (IOException ignored) {
// Ignored
}
}
} else {
request.setFixedLengthStreamingMode(0);
request.setRequestProperty("Content-Length", "0");
}
}
示例8: onHandleIntent
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
@Override
public void onHandleIntent(Intent i) {
try {
//checar se tem permissao... Android 6.0+
File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
root.mkdirs();
File output = new File(root, i.getData().getLastPathSegment());
if (output.exists()) {
output.delete();
}
URL url = new URL(i.getData().toString());
HttpURLConnection c = (HttpURLConnection) url.openConnection();
FileOutputStream fos = new FileOutputStream(output.getPath());
BufferedOutputStream out = new BufferedOutputStream(fos);
try {
InputStream in = c.getInputStream();
byte[] buffer = new byte[8192];
int len = 0;
while ((len = in.read(buffer)) >= 0) {
out.write(buffer, 0, len);
}
out.flush();
}
finally {
fos.getFD().sync();
out.close();
c.disconnect();
}
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DOWNLOAD_COMPLETE));
} catch (IOException e2) {
Log.e(getClass().getName(), "Exception durante download", e2);
}
}
示例9: copySo
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private static void copySo(InputStream input, OutputStream output) throws IOException {
BufferedInputStream bufferedInput = new BufferedInputStream(input);
BufferedOutputStream bufferedOutput = new BufferedOutputStream(output);
int count;
byte data[] = new byte[8192];
while ((count = bufferedInput.read(data, 0, 8192)) != -1) {
bufferedOutput.write(data, 0, count);
}
bufferedOutput.flush();
bufferedOutput.close();
output.close();
bufferedInput.close();
input.close();
}
示例10: 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();
}
示例11: extractFile
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private void extractFile(InputStream in, File outFile) throws IOException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile));
byte[] bytesIn = new byte[BUFFER_SIZE];
int read = 0;
while ((read = in.read(bytesIn)) != -1) {
bos.write(bytesIn, 0, read);
}
bos.close();
}
示例12: 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);
}
示例13: unzip
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static List<File> unzip(File file, String extension, File directory) throws IOException {
int bufferLength = 2048;
byte buffer[] = new byte[bufferLength];
List<File> foundFiles = new ArrayList<File>();
ZipInputStream zipInputStream = new ZipInputStream(
new BufferedInputStream(new FileInputStream(file)));
ZipEntry entry;
File tempDir = directory;
if (tempDir == null || !directory.isDirectory()) {
tempDir = File.createTempFile("unzipped" + UUID.randomUUID(), "", new File(System
.getProperty("java.io.tmpdir")));
tempDir.delete();
tempDir.mkdir();
}
while ((entry = zipInputStream.getNextEntry()) != null) {
int count;
File entryFile = new File(tempDir, entry.getName());
entryFile.createNewFile();
FileOutputStream fos = new FileOutputStream(entryFile);
BufferedOutputStream dest = new BufferedOutputStream(fos,
bufferLength);
while ((count = zipInputStream.read(buffer, 0, bufferLength)) != -1) {
dest.write(buffer, 0, count);
}
dest.flush();
dest.close();
if (entry.getName().endsWith("." + extension)) {
foundFiles.add(entryFile);
}
}
zipInputStream.close();
deleteResources(file);
return foundFiles;
}
示例14: getAllChunks
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private List<Byte> getAllChunks(BufferedInputStream inStream, BufferedOutputStream proxyClientStream) throws IOException {
ArrayList<Byte> retList = new ArrayList<Byte>(10000);
List<Byte> chunk;
while (!isInterrupted && (chunk = getChunk(inStream, proxyClientStream)).size() != 0) {
retList.addAll(chunk);
}
// dirty hack:
byte[] appendBytes = "0\r\n".getBytes("ISO-8859-1");
for (int i = 0; i < appendBytes.length; i++) {
retList.add(new Byte(appendBytes[i]));
proxyClientStream.write((int)appendBytes[i]);
}
return retList;
}
示例15: processRequest
import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
// get the idPrefix from the request-stream
String key = request.getParameter(ImageTag.SESSION_ID_PREFIX_NAME);
if(log.isDebugEnabled())
log.debug("Image Server... idPrefix = " + key);
// get the image-contents & mimeType from the UserSession
UserSession us = UserSession.getUserSession(request);
byte[] imageContents = us.getImageContents(key);
String mimeType = us.getImageMimeType(key);
// Delete the image from the UserSession.. since it wud not be used anymore
us.removeImage(key);
// generate the output-stream
if(log.isDebugEnabled())
log.debug("Output Image Stream Type:" + mimeType );
response.setContentType(mimeType);
response.setContentLength(imageContents.length);
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
bos.write(imageContents);
bos.close();
if(log.isDebugEnabled())
log.debug("Finished Outputting");
}