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


Java ObjectOutputStream.close方法代码示例

本文整理汇总了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;
}
 
开发者ID:asms,项目名称:360w17g1,代码行数:26,代码来源:AbstractController.java

示例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);
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:24,代码来源:VentanaPrincipal.java

示例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");
  }
}
 
开发者ID:inferjay,项目名称:r8,代码行数:22,代码来源:DexCallSite.java

示例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();
	    }
	}
 
开发者ID:johndavidbustard,项目名称:RoughWorld,代码行数:22,代码来源:StoryInstance.java

示例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);
        }

    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:23,代码来源:HumanVsComputerThrottleController.java

示例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;
    }
}
 
开发者ID:Alienturnedhuman,项目名称:PearPlanner,代码行数:26,代码来源:StudyPlannerController.java

示例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);
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:18,代码来源:SeismoDbAdapter.java

示例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());
    }
}
 
开发者ID:NexusByte,项目名称:LotusCloud,代码行数:33,代码来源:PacketClient.java

示例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");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:Correctness.java

示例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);
}
 
开发者ID:mtommila,项目名称:apfloat,代码行数:14,代码来源:ApintTest.java

示例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);
	}
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:10,代码来源:StatisticalSummary.java

示例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];
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:JSR166TestCase.java

示例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`");
}
 
开发者ID:Azure,项目名称:acs-demos,代码行数:15,代码来源:Player.java

示例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();
}
 
开发者ID:eps4j,项目名称:eps4j-core,代码行数:10,代码来源:EPSComm.java

示例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));
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:13,代码来源:LCMSPeakBase.java


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