本文整理了Java中java.io.OutputStream.close()
方法的一些代码示例,展示了OutputStream.close()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OutputStream.close()
方法的具体详情如下:
包路径:java.io.OutputStream
类名称:OutputStream
方法名:close
[英]Closes this stream. Implementations of this method should free any resources used by the stream. This implementation does nothing.
[中]关闭此流。此方法的实现应该释放流使用的任何资源。这个实现什么都不做。
代码示例来源:origin: stackoverflow.com
InputStream in;
OutputStream out;
IOUtils.copy(in,out);
in.close();
out.close();
代码示例来源:origin: stackoverflow.com
public void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
代码示例来源:origin: neo4j/neo4j
@Override
void close() throws IOException
{
out.flush();
out.close();
}
}
代码示例来源:origin: alibaba/nacos
public static void writeStringToFile(File file, String data, String encoding)
throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(data.getBytes(encoding));
os.flush();
} finally {
if (null != os) {
os.close();
}
}
}
代码示例来源:origin: redisson/redisson
/**
* {@inheritDoc}
*/
public Sink write(Manifest manifest) throws IOException {
if (manifest != null) {
File target = new File(folder, JarFile.MANIFEST_NAME);
if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) {
throw new IOException("Could not create directory: " + target.getParent());
}
OutputStream outputStream = new FileOutputStream(target);
try {
manifest.write(outputStream);
} finally {
outputStream.close();
}
}
return this;
}
代码示例来源:origin: iBotPeaches/Apktool
public static void cpdir(File src, File dest) throws BrutException {
dest.mkdirs();
File[] files = src.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
File destFile = new File(dest.getPath() + File.separatorChar
+ file.getName());
if (file.isDirectory()) {
cpdir(file, destFile);
continue;
}
try {
InputStream in = new FileInputStream(file);
OutputStream out = new FileOutputStream(destFile);
IOUtils.copy(in, out);
in.close();
out.close();
} catch (IOException ex) {
throw new BrutException("Could not copy file: " + file, ex);
}
}
}
代码示例来源:origin: apache/rocketmq
public static void writeStringToFile(File file, String data, String encoding) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream(file);
os.write(data.getBytes(encoding));
} finally {
if (null != os) {
os.close();
}
}
}
}
代码示例来源:origin: bumptech/glide
/**
* Flushes any pending data and closes output file. If writing to an
* OutputStream, the stream is not closed.
*/
public boolean finish() {
if (!started)
return false;
boolean ok = true;
started = false;
try {
out.write(0x3b); // GIF trailer
out.flush();
if (closeStream) {
out.close();
}
} catch (IOException e) {
ok = false;
}
// reset for subsequent use
transIndex = 0;
out = null;
image = null;
pixels = null;
indexedPixels = null;
colorTab = null;
closeStream = false;
firstFrame = true;
return ok;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Copy the contents of the given byte array to the given OutputStream.
* Closes the stream when done.
* @param in the byte array to copy from
* @param out the OutputStream to copy to
* @throws IOException in case of I/O errors
*/
public static void copy(byte[] in, OutputStream out) throws IOException {
Assert.notNull(in, "No input byte array specified");
Assert.notNull(out, "No OutputStream specified");
try {
out.write(in);
}
finally {
try {
out.close();
}
catch (IOException ex) {
}
}
}
代码示例来源:origin: iBotPeaches/Apktool
public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException {
try {
InputStream in = clazz.getResourceAsStream(resourcePath);
if (in == null) {
throw new FileNotFoundException(resourcePath);
}
File fileOut = File.createTempFile(tmpPrefix, null);
fileOut.deleteOnExit();
OutputStream out = new FileOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();
return fileOut;
} catch (IOException ex) {
throw new BrutException("Could not extract resource: " + resourcePath, ex);
}
}
}
代码示例来源:origin: libgdx/libgdx
public void flush () {
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
properties.storeToXML(out, null);
} catch (Exception ex) {
throw new RuntimeException("Error writing preferences: " + file, ex);
} finally {
if (out != null)
try {
out.close();
} catch (IOException e) {
}
}
}
代码示例来源:origin: redisson/redisson
final void process(Socket clnt) throws IOException {
InputStream in = new BufferedInputStream(clnt.getInputStream());
String cmd = readLine(in);
logging(clnt.getInetAddress().getHostName(),
new Date().toString(), cmd);
while (skipLine(in) > 0){
}
OutputStream out = new BufferedOutputStream(clnt.getOutputStream());
try {
doReply(in, out, cmd);
}
catch (BadHttpRequest e) {
replyError(out, e);
}
out.flush();
in.close();
out.close();
clnt.close();
}
代码示例来源:origin: jenkinsci/jenkins
@Override
public void run() {
try {
try {
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) >= 0) {
out.write(buf, 0, len);
out.flush();
}
} finally {
in.close();
out.close();
}
} catch (IOException e) {
// TODO: what to do?
}
}
}
代码示例来源:origin: stackoverflow.com
// Assume block needs to be inside a Try/Catch block.
String path = Environment.getExternalStorageDirectory().toString();
OutputStream fOut = null;
Integer counter = 0;
File file = new File(path, "FitnessGirl"+counter+".jpg"); // the File to save , append increasing numeric counter to prevent files from getting overwritten.
fOut = new FileOutputStream(file);
Bitmap pictureBitmap = getImageBitmap(myurl); // obtaining the Bitmap
pictureBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate
fOut.flush(); // Not really required
fOut.close(); // do not forget to close the stream
MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
代码示例来源:origin: elastic/elasticsearch-hadoop
public void saveKeystore(String path) throws EsHadoopSecurityException, IOException {
OutputStream stream = null;
try {
stream = new FileOutputStream(new File(path));
saveKeystore(stream);
} finally {
if (stream != null) {
stream.close();
}
}
}
代码示例来源:origin: prestodb/presto
private void writeZone(File outputDir, DateTimeZoneBuilder builder, DateTimeZone tz) throws IOException {
if (ZoneInfoLogger.verbose()) {
System.out.println("Writing " + tz.getID());
}
File file = new File(outputDir, tz.getID());
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
OutputStream out = new FileOutputStream(file);
try {
builder.writeTo(tz.getID(), out);
} finally {
out.close();
}
// Test if it can be read back.
InputStream in = new FileInputStream(file);
DateTimeZone tz2 = DateTimeZoneBuilder.readFrom(in, tz.getID());
in.close();
if (!tz.equals(tz2)) {
System.out.println("*e* Error in " + tz.getID() +
": Didn't read properly from file");
}
}
代码示例来源:origin: libgdx/libgdx
private void writeFile (File outFile, byte[] bytes) {
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(outFile));
out.write(bytes);
} catch (IOException e) {
throw new RuntimeException("Couldn't write file '" + outFile.getAbsolutePath() + "'", e);
} finally {
if (out != null) try {
out.close();
} catch (IOException e) {
}
}
}
代码示例来源:origin: qiurunze123/miaosha
public static void out(HttpServletResponse res, String html){
res.setContentType("text/html");
res.setCharacterEncoding("UTF-8");
try{
OutputStream out = res.getOutputStream();
out.write(html.getBytes("UTF-8"));
out.flush();
out.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
代码示例来源:origin: jenkinsci/jenkins
public void close() throws IOException {
in.close();
out.close();
}
}
代码示例来源:origin: libgdx/libgdx
/** Writes the specified bytes to the file. Parent directories will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throw RuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* FileType#Internal file, or if it could not be written. */
public void writeBytes (byte[] bytes, boolean append) {
OutputStream output = write(append);
try {
output.write(bytes);
} catch (IOException ex) {
throw new RuntimeException("Error writing file: " + file + " (" + type + ")", ex);
} finally {
try {
output.close();
} catch (IOException ignored) {
}
}
}
内容来源于网络,如有侵权,请联系作者删除!