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


Java ObjectOutputStream.writeObject方法代码示例

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


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

示例1: doReps

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
 * Run benchmark for given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, ObjectStreamClass[] descs, int ncycles)
    throws Exception
{
    int ndescs = descs.length;
    for (int i = 0; i < ncycles; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ndescs; j++) {
            oout.writeObject(descs[j]);
        }
        oout.flush();
        for (int j = 0; j < ndescs; j++) {
            oin.readObject();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ProxyClassDesc.java

示例2: doReps

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
 * Run benchmark for given number of batches, with each batch containing
 * the given number of cycles.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, Node[] trees, int nbatches)
    throws Exception
{
    int ncycles = trees.length;
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        oout.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeObject(trees[j]);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readObject();
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:CustomObjTrees.java

示例3: serialize

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static final byte[] serialize(Object value, Object meta, boolean insertMeta) {
	if (value == null) {
		return new byte[0];
	}

	// Try to serialize content (type-safe serialization)
	if ((value == null || value instanceof Serializable) && (meta == null || meta instanceof Serializable)) {
		Map<Object, Object> map = insertMeta(value, meta, insertMeta);
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
			baos.write(1);
			ObjectOutputStream oos = new ObjectOutputStream(baos);
			oos.writeObject(value);
			oos.flush();
			return baos.toByteArray();
		} catch (Throwable ignored) {
		} finally {
			removeMeta(map);
		}
	}

	// Write content as JSON
	byte[] bytes = TreeWriterRegistry.getWriter(null).toString(value, meta, false, insertMeta)
			.getBytes(StandardCharsets.UTF_8);
	byte[] copy = new byte[bytes.length + 1];
	System.arraycopy(bytes, 0, copy, 1, bytes.length);
	return copy;
}
 
开发者ID:berkesa,项目名称:datatree,代码行数:29,代码来源:JavaBuiltin.java

示例4: writeObject

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
 * @serialData Null terminated list of <code>PropertyChangeListeners</code>.
 * <p>
 * At serialization time we skip non-serializable listeners and
 * only serialize the serializable listeners.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    Hashtable<String, PropertyChangeSupport> children = null;
    PropertyChangeListener[] listeners = null;
    synchronized (this.map) {
        for (Entry<String, PropertyChangeListener[]> entry : this.map.getEntries()) {
            String property = entry.getKey();
            if (property == null) {
                listeners = entry.getValue();
            } else {
                if (children == null) {
                    children = new Hashtable<>();
                }
                PropertyChangeSupport pcs = new PropertyChangeSupport(this.source);
                pcs.map.set(null, entry.getValue());
                children.put(property, pcs);
            }
        }
    }
    ObjectOutputStream.PutField fields = s.putFields();
    fields.put("children", children);
    fields.put("source", this.source);
    fields.put("propertyChangeSupportSerializedDataVersion", 2);
    s.writeFields();

    if (listeners != null) {
        for (PropertyChangeListener l : listeners) {
            if (l instanceof Serializable) {
                s.writeObject(l);
            }
        }
    }
    s.writeObject(null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:PropertyChangeSupport.java

示例5: object2Byte

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static byte[] object2Byte(Object obj) {
    byte[] bytes = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(obj);
        oos.flush();
        bytes = bos.toByteArray();
        oos.close();
        bos.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return bytes;
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:16,代码来源:IOUtil.java

示例6: saveHistogramToFile

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public void saveHistogramToFile(File file) throws IOException, FileNotFoundException {
    log.info("Saving histogram data to " + file.getName());
    FileOutputStream fos = new FileOutputStream(file);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(histogram.length);
    oos.writeObject(histogram);
    oos.writeObject(bitmap);
    oos.writeFloat(threshold);
    oos.close();
    fos.close();
    log.info("histogram saved to file " + file.getPath());
    setFilePath(file.getPath());
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:14,代码来源:Histogram2DFilter.java

示例7: object2bytes

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
 * 对象序列化转换为byte数组
 * 
 * @param obj
 * @return
 * @throws IOException
 */
byte[] object2bytes(Object obj) throws IOException {
	if (obj == null) {
		return null;
	}
	// 值对象转换为byte[]
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ObjectOutputStream oos = new ObjectOutputStream(baos);
	oos.writeObject(obj);
	oos.close();
	byte[] bytes = baos.toByteArray();
	baos.close();
	return bytes;
}
 
开发者ID:AlexLee-CN,项目名称:weixin_api,代码行数:21,代码来源:Storage.java

示例8: MutablePeriod

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public MutablePeriod() {
	try {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		ObjectOutputStream out = new ObjectOutputStream(bos);

		// Serialize a valid Period instance
		out.writeObject(new Period(new Date(), new Date()));

		/*
		 * Append rogue "previous object refs" for internal Date fields in
		 * Period. For details, see "Java Object Serialization
		 * Specification," Section 6.4.
		 */
		byte[] ref = { 0x71, 0, 0x7e, 0, 5 }; // Ref #5
		bos.write(ref); // The start field
		ref[4] = 4; // Ref # 4
		bos.write(ref); // The end field

		// Deserialize Period and "stolen" Date references
		ObjectInputStream in = new ObjectInputStream(
				new ByteArrayInputStream(bos.toByteArray()));
		period = (Period) in.readObject();
		start = (Date) in.readObject();
		end = (Date) in.readObject();
	} catch (Exception e) {
		throw new AssertionError(e);
	}
}
 
开发者ID:turoDog,项目名称:effectiveJava,代码行数:29,代码来源:MutablePeriod.java

示例9: testSubscriptionAttributesAreSerializable

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
/**
 * Assert that SubscriptionAttributes are serializable.
 */
@Test
public void testSubscriptionAttributesAreSerializable() throws Exception {
  SubscriptionAttributes outSA = new SubscriptionAttributes();
  ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
  ObjectOutputStream oos = new ObjectOutputStream(baos);
  oos.writeObject(outSA);

  byte[] data = baos.toByteArray();

  ByteArrayInputStream bais = new ByteArrayInputStream(data);
  ObjectInputStream ois = new ObjectInputStream(bais);
  SubscriptionAttributes inSA = (SubscriptionAttributes) ois.readObject();
  assertEquals(outSA, inSA);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:18,代码来源:MembershipAttributesAreSerializableTest.java

示例10: writeObject

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeObject(this.cookie.getName());
    out.writeObject(this.cookie.getValue());
    out.writeObject(this.cookie.getComment());
    out.writeObject(this.cookie.getDomain());
    out.writeObject(this.cookie.getExpiryDate());
    out.writeObject(this.cookie.getPath());
    out.writeInt(this.cookie.getVersion());
    out.writeBoolean(this.cookie.isSecure());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:SerializableCookie.java

示例11: serialClone

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static <T> T serialClone(T obj) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(obj);
        oos.close();
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        return (T) ois.readObject();
    } catch (IOException | ClassNotFoundException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:MapFactories.java

示例12: flush

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static synchronized void flush() throws FileNotFoundException,
		IOException {
	if (flushCounter > 0 && resultsCacheFilename != null) {
		LOG.info("Flushing relatedness cache... ");
		new File(resultsCacheFilename).createNewFile();
		ObjectOutputStream oos = new ObjectOutputStream(
				new FileOutputStream(resultsCacheFilename));
		oos.writeObject(instance);
		oos.close();
		LOG.info("Flushing relatedness cache done.");
	}
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:13,代码来源:WATRelatednessComputer.java

示例13: savePrefs

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
static void savePrefs(String f, DataAccessPoint sourceDb,
                      DataAccessPoint targetDb, Traceable tracer,
                      Vector tTable) {

    TransferTable t;

    try {
        FileOutputStream   fos = new FileOutputStream(f);
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        for (int i = 0; i < tTable.size(); i++) {
            t          = (TransferTable) tTable.elementAt(i);
            t.sourceDb = null;
            t.destDb   = null;
            t.tracer   = null;
        }

        oos.writeObject(tTable);

        for (int i = 0; i < tTable.size(); i++) {
            t          = (TransferTable) tTable.elementAt(i);
            t.tracer   = tracer;
            t.sourceDb = (TransferDb) sourceDb;
            t.destDb   = targetDb;
        }
    } catch (IOException e) {
        System.out.println("pb in SavePrefs : " + e.toString());
        e.printStackTrace();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:31,代码来源:TransferCommon.java

示例14: writeSpectralAtomsAndEnvelopes

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public static void writeSpectralAtomsAndEnvelopes(SpectralAtomsAndEnvelopes spectralAtomsAndEnvelopes, String path) {
	try {
		FileOutputStream fileOut = new FileOutputStream(path);
		ObjectOutputStream out = new ObjectOutputStream(fileOut);
		out.writeObject(spectralAtomsAndEnvelopes);
		out.close();
		fileOut.close();
	} catch(IOException i) {
		i.printStackTrace();
	}
}
 
开发者ID:tberg12,项目名称:klavier,代码行数:12,代码来源:DatasetIO.java

示例15: copy

import java.io.ObjectOutputStream; //导入方法依赖的package包/类
public EventSummaryConfigModel copy() throws IOException, ClassNotFoundException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
    objectOutputStream.writeObject(this);
    ByteArrayInputStream
        byteArrayInputStream =
        new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    return (EventSummaryConfigModel) objectInputStream.readObject();

}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:12,代码来源:EventSummaryConfigModel.java


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