当前位置: 首页>>代码示例>>Java>>正文


Java BufferedOutputStream.flush方法代码示例

本文整理汇总了Java中java.io.BufferedOutputStream.flush方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedOutputStream.flush方法的具体用法?Java BufferedOutputStream.flush怎么用?Java BufferedOutputStream.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.BufferedOutputStream的用法示例。


在下文中一共展示了BufferedOutputStream.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: displayPDF

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
private void displayPDF() throws IOException {
    HttpServletResponse response = (HttpServletResponse) this.facesContext
            .getExternalContext().getResponse();

    response.reset();
    response.setContentType(this.contentType);
    response.setContentLength(this.content.length);

    response.addHeader("Content-Disposition",
            this.getDisplayType(this.displayType) + "; " + "filename="
                    + this.filename);
    response.addHeader("Accept-Ranges", "bytes");

    BufferedOutputStream outputStream = new BufferedOutputStream(
            response.getOutputStream());
    outputStream.write(this.content);
    outputStream.flush();
    outputStream.close();

    facesContext.responseComplete();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:22,代码来源:ExternalPriceModelDisplayHandler.java

示例2: 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();
}
 
开发者ID:lslxy1021,项目名称:FileOperation,代码行数:19,代码来源:BMerge.java

示例3: 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();
}
 
开发者ID:Jugendhackt,项目名称:OpenVertretung,代码行数:23,代码来源:BlobTest.java

示例4: downloadFile

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static boolean downloadFile(URL url, File path, boolean overwrite) throws IOException {
	InputStream is = url.openStream();
	if (overwrite && path.exists())
		overwrite(path);
	BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(path));
	byte[] buff = new byte[1024];
	int rb = 0;
	while ((rb = is.read(buff)) != -1) {
		fos.write(buff, 0, rb);
	}
	fos.flush();
	fos.close();
	return true;
}
 
开发者ID:biancso,项目名称:Mevius-IO,代码行数:15,代码来源:FileUtils.java

示例5: saveBitmapFile

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
 * 把batmap 转file
 * @param bitmap
 * @param filepath
 */
public static File saveBitmapFile(Bitmap bitmap, String filepath){
    File file=new File(filepath);//将要保存图片的路径
    try {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(CompressFormat.JPEG, 100, bos);
        bos.flush();
        bos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:18,代码来源:MyBitmapUtil.java

示例6: sendData

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static void sendData(Socket socket, SecurityMode security, byte[] data) throws IOException {
    BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());
    byte[] body = security.encrypt(data);
    byte[] head = ByteTool.intToByteArray(body.length);
    bos.write(head);
    bos.flush();
    bos.write(body);
    bos.flush();
}
 
开发者ID:Thoxvi,项目名称:WarriorsClipboard_Server,代码行数:10,代码来源:NetTool.java

示例7: 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);
}
 
开发者ID:funtl,项目名称:framework,代码行数:36,代码来源:StorageManager.java

示例8: exportTorchNet

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
 * I never got the torch net loading from assets/apk working (apkascii, apkbinary), so this is
 * my workaround. The net is exported to the private files directory. The returned path is
 * dynamically used when loading the torch model in lua.
 *
 * Hint; This should not be performed on the main thread, just keeping the api simple.
 */
private String exportTorchNet(Context c) {
    File output = new File(c.getFilesDir(), "mockAsciiNet.net");

    if (!output.exists()) {
        try {
            BufferedInputStream source = new BufferedInputStream(c.getAssets().open("mockAsciiNet.net"));
            BufferedOutputStream sink = new BufferedOutputStream(new FileOutputStream(output));

            byte[] buf = new byte[512];
            int read = 0;
            while (read != -1) {
                read = source.read(buf, 0, 512);

                if (read != -1)
                    sink.write(buf, 0, read);
            }

            sink.flush();
            sink.close();
            source.close();
        } catch (Exception e) {
            throw new RuntimeException("Failed to export .net", e);
        }
    }

    return output.getAbsolutePath();
}
 
开发者ID:paramsen,项目名称:torch-android-studio-template,代码行数:35,代码来源:JNIBridge.java

示例9: 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['ࠀ'];
	BufferedInputStream bis = new BufferedInputStream(is, 8192);
	try {
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpFile), 8192);

		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, 1);
		}

		state = saveTmpFile(tmpFile, path);

		if (!state.isSuccess()) {
			tmpFile.delete();
		}

		return state;
	} catch (IOException localIOException) {
	}

	return new BaseState(false, 4);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:35,代码来源:StorageManager.java

示例10: writeTo

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
 * Writes all bytes to the given stream.
 * 
 * @param stream
 *            to be written to
 * @param value
 *            to be written to the given stream
 * @throws IOException
 * @throws InterruptedException
 */
public static void writeTo(OutputStream stream, byte[] value)
        throws IOException, InterruptedException {
    BufferedOutputStream os = new BufferedOutputStream(stream);
    try {
        for (byte element : value) {
            Streams.checkIfCanceled();
            os.write(element);
        }
        os.flush();
    } finally {
        close(os);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:Streams.java

示例11: importFile

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
@VisibleForTesting
public long importFile(String userId, long projectId, String fileName,
    InputStream uploadedFileStream) throws FileImporterException, IOException {
  int maxAssetSizeBytes = (int) (maxAssetSizeMegs.get() * 1024 * 1024);
  int maxSizeBytes = Math.min(maxAssetSizeBytes, storageIo.getMaxJobSizeBytes());

  BufferedInputStream bis = new BufferedInputStream(uploadedFileStream);
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  BufferedOutputStream bos = new BufferedOutputStream(os);

  // Alledgedly since it is buffered, reading in units of one byte
  // should be as fast as many bytes, but we can always adjust this.
  int bytes = 0;
  long fileLength = 0;
  byte[] buffer = new byte[1];
  while ((bytes = bis.read(buffer, 0, buffer.length)) != -1) {
    bos.write(buffer, 0, bytes);
    fileLength += bytes;
  }
  bos.flush();

  // First check the file length, to avoid loading the file into memory if it is too large anyhow.
  if (fileLength > maxSizeBytes) {
    throw new FileImporterException(UploadResponse.Status.FILE_TOO_LARGE);
  }

  byte[] content = os.toByteArray();

  // If the file already exists, we will overwrite the content.
  List<String> sourceFiles = storageIo.getProjectSourceFiles(userId, projectId);
  if (!sourceFiles.contains(fileName)) {
    storageIo.addSourceFilesToProject(userId, projectId, false, fileName);
  }
  return storageIo.uploadRawFileForce(projectId, fileName, userId, content);
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:36,代码来源:FileImporterImpl.java

示例12: saveToFile

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static void saveToFile(InputStream in, File file) throws IOException {
    File outputFile= file;
    outputFile.deleteOnExit();
    outputFile.getParentFile().mkdirs();
    BufferedOutputStream outputStream=new BufferedOutputStream(new FileOutputStream(outputFile));
    byte[] buffer=new byte[2048];
    int length=in.read(buffer);
    while (length!=-1){
        outputStream.write(buffer,0,length);
        length=in.read(buffer);
    }
    outputStream.flush();
    outputStream.close();
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:15,代码来源:IOUtil.java

示例13: saveBitmapFile

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
/**
 * bitmap转file
 */

public static File saveBitmapFile(Bitmap bitmap) {
    File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/img.png");//将要保存图片的路径
    try {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
        bos.flush();
        bos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}
 
开发者ID:linsir6,项目名称:AndroidCameraUtil,代码行数:17,代码来源:Util.java

示例14: uncompress

import java.io.BufferedOutputStream; //导入方法依赖的package包/类
public static boolean uncompress(File zipFile) {
    boolean success = false;
    try {
        FileInputStream fis = new FileInputStream(zipFile);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry;
        File destFolder = new File(zipFile.getParent(), FileUtils.getNameFromFilename(zipFile.getName()));
        destFolder.mkdirs();
        while ((entry = zis.getNextEntry()) != null) {
            File dest = new File(destFolder, entry.getName());
            dest.getParentFile().mkdirs();

            if(entry.isDirectory()) {
                if (!dest.exists()) {
                    dest.mkdirs();
                }
            } else {
                int size;
                byte[] buffer = new byte[2048];
                FileOutputStream fos = new FileOutputStream(dest);
                BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length);
                while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                    bos.write(buffer, 0, size);
                }
                bos.flush();
                bos.close();
                IoUtils.flushQuietly(bos);
                IoUtils.closeQuietly(bos);
            }
            zis.closeEntry();
        }
        IoUtils.closeQuietly(zis);
        IoUtils.closeQuietly(fis);
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return success;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:40,代码来源:FileUtils.java

示例15: 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);
    }
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:37,代码来源:DownloadService.java


注:本文中的java.io.BufferedOutputStream.flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。