本文整理汇总了Java中java.io.ObjectOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectOutputStream.close方法的具体用法?Java ObjectOutputStream.close怎么用?Java ObjectOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.ObjectOutputStream
的用法示例。
在下文中一共展示了ObjectOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serializeToDisk
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Serializes an object and writes it to the disk.
* <p>The file written will match the pattern "KEYNAME_CLASSNAME.ser"</p>
*
* @param theKey the key name associated with the object
* @param theObject the object to serialize
* @return true if the operation completed successfully
*/
public static final <E extends Serializable> boolean serializeToDisk(final String theKey, final E theObject) {
boolean succeeded;
try {
final File file = new File(theKey + "_" + theObject.getClass().getSimpleName() + ".ser");
if (!file.exists()) {
file.createNewFile();
}
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(theObject);
oos.close();
succeeded = true;
} catch (final Exception theException) {
//System.err.println(theException.getMessage());
succeeded = false;
}
return succeeded;
}
示例2: jButtonDetenerActionPerformed
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
private void jButtonDetenerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDetenerActionPerformed
try {
// Se intenta conectar, retorna IOException en caso que no pueda
Socket socket = new Socket(servidor, numeroPuerto);
// Stream para e/s, se crea primero la salida
ObjectOutputStream salida = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream entrada = new ObjectInputStream(socket.getInputStream());
salida.writeObject("Mata server" + id);
jLabel1.setForeground(Color.red);
entrada.close();
salida.close();
socket.close();
url.setText("");
jlabelSQL.setText("");
this.setTitle("App [ID:?]");
} catch (IOException ex) {
System.out.println("(LOG) [ERROR] No se pudo contactar al servidor");
Logger.getLogger(VentanaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例3: build
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
String build() {
try {
bytes = new ByteArrayOutputStream();
out = new ObjectOutputStream(bytes);
// We will generate SHA-1 hash of the call site information based on call site
// attributes used in equality comparison, such that if the two call sites are
// different their hashes should also be different.
write(methodName);
write(methodProto);
write(bootstrapMethod);
write(bootstrapArgs);
out.close();
MessageDigest digest = MessageDigest.getInstance("SHA-1");
digest.update(bytes.toByteArray());
return BaseEncoding.base64Url().omitPadding().encode(digest.digest());
} catch (NoSuchAlgorithmException | IOException ex) {
throw new Unreachable("Cannot get SHA-1 message digest");
}
}
示例4: saveObject
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static void saveObject(StoryInstance o,FileStoreInterface fs,String path)
{
try {
fs.rename(path, "~"+path);
// File fout = new File(path);
// if(fout.exists())
// fout.delete();
FileOutputStream fileOut =
new FileOutputStream(path);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(o);
out.close();
fileOut.close();
StateToXML.objectToXMLFile(o);
}
catch(IOException i)
{
i.printStackTrace();
}
}
示例5: doSaveThrottleSettings
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
synchronized public void doSaveThrottleSettings() {
if (currentProfile == null) {
log.warning("no profile to save");
return;
}
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(currentProfile.numPoints);
oos.writeObject(currentProfile.throttleValues);
putByteArray("throttleProfile", bos.toByteArray());
oos.close();
bos.close();
log.info("throttle settings saveed to preferences");
log.info("current throttle profile is "+currentProfile.toString());
} catch (Exception e) {
log.warning("couldn't save profile: " + e);
}
}
示例6: save
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Save the current StudyPlanner into a serialized file.
*
* @param key64 SecretKey used for encoding.
* @param fileName name of the file.
* @return whether saved successfully.
*/
public boolean save(SecretKey key64, String fileName)
{
try
{
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, key64);
SealedObject sealedObject = new SealedObject(this.planner, cipher);
CipherOutputStream cipherOutputStream = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)), cipher);
ObjectOutputStream outputStream = new ObjectOutputStream(cipherOutputStream);
outputStream.writeObject(sealedObject);
outputStream.close();
return true;
} catch (Exception e)
{
e.printStackTrace();
return false;
}
}
示例7: createGraph
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public long createGraph(String name, ArrayList<ArrayList<Float>> graph) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
ObjectOutputStream objects = new ObjectOutputStream(bytes);
objects.writeObject(graph);
objects.close();
bytes.close();
} catch (IOException e) {
// Do nothing.
}
ContentValues initial_values = new ContentValues();
initial_values.put(KEY_TITLE, name);
initial_values.put(KEY_BODY, bytes.toByteArray());
return db_.insert(DATABASE_TABLE, null, initial_values);
}
示例8: request
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static Packet request(String host, int port, Packet packet) {
KeyPair keyPair = Crypter.generateKeyPair();
try {
Socket socket = new Socket(host, port);
if (socket.isClosed()) {
return new ErrorPacket("socket closed");
}
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
out.writeObject(keyPair.getPublic());
PublicKey publicKey = (PublicKey) in.readObject();
SecretKey key = Crypter.generateEC(keyPair.getPrivate(), publicKey);
out.writeObject(Crypter.encrypt(key, Crypter.toByteArray(packet)));
out.flush();
Packet response = (Packet) Crypter.toObject(Crypter.decrypt(key, (byte[]) in.readObject()));
in.close();
out.close();
socket.close();
return response;
} catch (Exception ex) {
return new ErrorPacket(ex.getMessage());
}
}
示例9: main
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String SIGALG = "SHA1withRSA";
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
KeyPair kp = kpg.generateKeyPair();
SignedObject so1 = new SignedObject("Hello", kp.getPrivate(),
Signature.getInstance(SIGALG));
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(so1);
out.close();
byte[] data = byteOut.toByteArray();
SignedObject so2 = (SignedObject)new ObjectInputStream(
new ByteArrayInputStream(data)).readObject();
if (!so2.getObject().equals("Hello")) {
throw new Exception("Content changed");
}
if (!so2.getAlgorithm().equals(SIGALG)) {
throw new Exception("Signature algorithm unknown");
}
if (!so2.verify(kp.getPublic(), Signature.getInstance(SIGALG))) {
throw new Exception("Not verified");
}
}
示例10: testSerialization
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static void testSerialization()
throws IOException, ClassNotFoundException
{
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
Apint a = new Apint(5);
out.writeObject(a);
out.close();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
Apint b = (Apint) in.readObject();
assertEquals("5 equals", a, b);
assertNotSame("5 !=", a, b);
}
示例11: save
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public void save(String path) {
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path));
oos.writeObject(this);
oos.close();
} catch (Exception e) {
System.out.println(e);
}
}
示例12: serialBytes
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
byte[] serialBytes(Object o) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(o);
oos.flush();
oos.close();
return bos.toByteArray();
} catch (Throwable fail) {
threadUnexpectedException(fail);
return new byte[0];
}
}
示例13: save
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
* Save the Player object so that we can load it dynamically at
* application startup.
* @throws IOException
*/
public void save() throws IOException {
String filename = getName() + ".player";
FileOutputStream fileOut = new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(this);
out.close();
fileOut.close();
logger.info("Serialized Player in `test_1.player`");
}
示例14: serialize
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
private static byte[] serialize(Serializable object) throws IOException {
bos.reset();
final ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(object);
oos.flush();
oos.close();
bos.flush();
return bos.toByteArray();
}
示例15: JavaSerializationPeakClusterWrite
import java.io.ObjectOutputStream; //导入方法依赖的package包/类
private void JavaSerializationPeakClusterWrite() {
try {
Logger.getRootLogger().info("Writing PeakCluster serialization to file:" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser...");
FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(ParentmzXMLName) + FilenameUtils.getBaseName(ParentmzXMLName) + "_Peak/" + FilenameUtils.getBaseName(ScanCollectionName) + "_PeakCluster.ser", false);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(PeakClusters);
oos.close();
fout.close();
} catch (Exception ex) {
Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex));
}
}