java.io.ObjectOutputStream.close()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中java.io.ObjectOutputStream.close()方法的一些代码示例,展示了ObjectOutputStream.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectOutputStream.close()方法的具体详情如下:
包路径:java.io.ObjectOutputStream
类名称:ObjectOutputStream
方法名:close

ObjectOutputStream.close介绍

[英]Closes this stream. Any buffered data is flushed. This implementation closes the target stream.
[中]关闭此流。任何缓冲数据都会被刷新。此实现关闭目标流。

代码示例

代码示例来源:origin: stackoverflow.com

FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(this);
os.close();
fos.close();

代码示例来源:origin: junit-team/junit4

private void save() throws IOException {
  ObjectOutputStream stream = null;
  try {
    stream = new ObjectOutputStream(new FileOutputStream(fHistoryStore));
    stream.writeObject(this);
  } finally {
    if (stream != null) {
      stream.close();
    }
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

@SneakyThrows
private InputStream getInputStream(final Object value) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
  objectOutputStream.writeObject(value);
  objectOutputStream.flush();
  objectOutputStream.close();
  return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
}

代码示例来源:origin: apache/storm

public static byte[] serializeKerberosTicket(KerberosTicket tgt) throws Exception {
  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  ObjectOutputStream out = new ObjectOutputStream(bao);
  out.writeObject(tgt);
  out.flush();
  out.close();
  return bao.toByteArray();
}

代码示例来源:origin: google/j2objc

private void save() throws IOException {
  ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(
      fHistoryStore));
  stream.writeObject(this);
  stream.close();
}

代码示例来源:origin: apache/storm

public static byte[] javaSerialize(Object obj) {
  try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(obj);
    oos.close();
    return bos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static <T> void serializeCounter(Counter<T> c, String filename) throws IOException {
 // serialize to file
 ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
 out.writeObject(c);
 out.close();
}

代码示例来源:origin: apache/incubator-shardingsphere

@SneakyThrows
protected InputStream getInputStream(final Object value) {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
  objectOutputStream.writeObject(value);
  objectOutputStream.flush();
  objectOutputStream.close();
  return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
}

代码示例来源:origin: stanfordnlp/CoreNLP

public static void outputModel(String fileName, Classifier<String, String> clf) {
 FileOutputStream fo = null;
 try {
  fo = new FileOutputStream(fileName);
  ObjectOutputStream so = new ObjectOutputStream(fo);
  so.writeObject(clf);
  so.flush();
  so.close();
 } catch (FileNotFoundException e) {
  e.printStackTrace();
 } catch (IOException e) {
  e.printStackTrace();
 }
}

代码示例来源:origin: apache/storm

@Override
public byte[] serialize(Object object) {
  try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream gos = new GZIPOutputStream(bos);
    ObjectOutputStream oos = new ObjectOutputStream(gos);
    oos.writeObject(object);
    oos.close();
    return bos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: stackoverflow.com

File file = new File(getDir("data", MODE_PRIVATE), "map");    
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
outputStream.writeObject(map);
outputStream.flush();
outputStream.close();

代码示例来源:origin: alibaba/jstorm

@Override
public byte[] serialize(Object object) {
  try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(object);
    oos.close();
    return bos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

public void save(String path) throws IOException {
 // save the CRF
 this.classifier.serializeClassifier(path);
 // save the additional arguments
 FileOutputStream fos = new FileOutputStream(path + ".extra");
 ObjectOutputStream out = new ObjectOutputStream(fos);
 out.writeObject(this.gazetteerLocation);
 out.writeObject(this.annotationsToSkip);
 out.writeObject(this.useSubTypes);
 out.writeObject(this.useBIO);
 out.close();
}

代码示例来源:origin: redisson/redisson

private static String calcClassSign(String name) {
  try {
    Class<?> clazz = Class.forName(name);
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    ObjectOutputStream outputStream = new ObjectOutputStream(result);
    outputStream.writeObject(clazz);
    outputStream.close();
    MessageDigest crypt = MessageDigest.getInstance("SHA-1");
    crypt.reset();
    crypt.update(result.toByteArray());
    return new BigInteger(1, crypt.digest()).toString(16);
  } catch (Exception e) {
    throw new IllegalStateException("Can't calculate sign of " + name, e);
  }
}

代码示例来源:origin: stackoverflow.com

FileOutputStream fos = new FileOutputStream("t.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(clubs);
oos.close();

代码示例来源:origin: redisson/redisson

@Override
public Buffer apply(T t) {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try {
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(t);
    oos.flush();
    oos.close();
  } catch (IOException e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
  return Buffer.wrap(baos.toByteArray());
}

代码示例来源:origin: log4j/log4j

/**
 * Saves a list of MRU files out to a file.
 */
public void save() {
 File file = new File(getFilename());
 try {
  ObjectOutputStream oos = new ObjectOutputStream(new
    FileOutputStream(file));
  oos.writeObject(_mruFileList);
  oos.flush();
  oos.close();
 } catch (Exception e) {
  // do nothing
  e.printStackTrace();
 }
}

代码示例来源:origin: redisson/redisson

private static String calcClassSign(String name) {
  try {
    Class<?> clazz = Class.forName(name);
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    ObjectOutputStream outputStream = new ObjectOutputStream(result);
    outputStream.writeObject(clazz);
    outputStream.close();
    MessageDigest crypt = MessageDigest.getInstance("SHA-1");
    crypt.reset();
    crypt.update(result.toByteArray());
    return new BigInteger(1, crypt.digest()).toString(16);
  } catch (Exception e) {
    throw new IllegalStateException("Can't calculate sign of " + name, e);
  }
}

代码示例来源:origin: guoguibing/librec

public static void serialize(Object obj, String filePath) throws Exception {
  FileOutputStream fos = new FileOutputStream(filePath);
  ObjectOutputStream oos = new ObjectOutputStream(fos);
  oos.writeObject(obj);
  oos.flush();
  oos.close();
  fos.close();
}

代码示例来源:origin: redisson/redisson

private static String calcClassSign(String name) {
  try {
    Class<?> clazz = Class.forName(name);
    ByteArrayOutputStream result = new ByteArrayOutputStream();
    ObjectOutputStream outputStream = new ObjectOutputStream(result);
    outputStream.writeObject(clazz);
    outputStream.close();
    MessageDigest crypt = MessageDigest.getInstance("SHA-1");
    crypt.reset();
    crypt.update(result.toByteArray());
    return new BigInteger(1, crypt.digest()).toString(16);
  } catch (Exception e) {
    throw new IllegalStateException("Can't calculate sign of " + name, e);
  }
}

相关文章

ObjectOutputStream类方法