/** * {@inheritDoc} */ @Override public void flush() throws IOException { this.out.flush(); }
@Override public void flush() throws IOException { out.flush(); }
@Override public void flush() throws IOException { out.flush(); }
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(yourObject); out.flush(); byte[] yourBytes = bos.toByteArray(); ... } finally { try { bos.close(); } catch (IOException ex) { // ignore close exception } }
@Override public byte[] serialize(Object resultValue) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bos)) { out.writeObject(resultValue); out.flush(); return bos.toByteArray(); } catch (Exception ex) { log.info("Exception during serialization", ex); } return null; }
public void writeExternal(ObjectOutput out) throws IOException { out.writeInt(_bitSize); out.writeInt(_mask); out.writeObject(_bits); out.flush(); }
@Override public byte[] serialize(final Object obj) throws HmilyException { try (ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); ObjectOutput objectOutput = new ObjectOutputStream(arrayOutputStream)) { objectOutput.writeObject(obj); objectOutput.flush(); return arrayOutputStream.toByteArray(); } catch (IOException e) { throw new HmilyException("java serialize error " + e.getMessage()); } }
@Override public byte[] serialize(final Object obj) throws TransactionException { try (ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); ObjectOutput objectOutput = new ObjectOutputStream(arrayOutputStream)) { objectOutput.writeObject(obj); objectOutput.flush(); return arrayOutputStream.toByteArray(); } catch (IOException e) { throw new TransactionException("java serialize error " + e.getMessage()); } }
/** * 保存模型 */ public void saveModel(String filePath) throws IOException { ObjectOutput oot = new ObjectOutputStream(new FileOutputStream(filePath)); oot.writeObject(this); oot.flush(); oot.close(); }
@Override public byte[] serialize(final Object obj) throws MythException { try (ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); ObjectOutput objectOutput = new ObjectOutputStream(arrayOutputStream)) { objectOutput.writeObject(obj); objectOutput.flush(); return arrayOutputStream.toByteArray(); } catch (IOException e) { throw new MythException("java serialize error " + e.getMessage()); } }
/** * The object implements the writeExternal method to save its contents * by calling the methods of DataOutput for its primitive values or * calling the writeObject method of ObjectOutput for objects, strings * and arrays. * * @param out the ObjectOutput object to write to * @exception IOException Includes any I/O exceptions that may occur */ public void writeExternal(ObjectOutput out) throws IOException { out.writeUTF(toString()); out.flush(); }
/** * Wraps native split. * * @param id Split ID. * @param split Split. * @param hosts Hosts. * @throws IOException If failed. */ public static HadoopSplitWrapper wrapSplit(int id, Object split, String[] hosts) throws IOException { ByteArrayOutputStream arr = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(arr); assert split instanceof Writable; ((Writable)split).write(out); out.flush(); return new HadoopSplitWrapper(id, split.getClass().getName(), arr.toByteArray(), hosts); }
/** {@inheritDoc} */ @Override public ByteBuffer marshal(Object obj, int off) throws IOException { GridByteArrayOutputStream bOut = new GridByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(bOut); out.writeObject(obj); out.flush(); ByteBuffer buf = ByteBuffer.allocate(off + bOut.size()); buf.position(off); buf.put(bOut.internalArray(), 0, bOut.size()); buf.flip(); return buf; }
public static void write(ObjectOutput out, Command cmd) throws IOException { out.writeByte(cmd.getType()); cmd.write(out); if (cmd.isUrgent()) { out.flush(); } } }
/** * 序列化dat对象 */ public void save(final String path) throws IOException { ObjectOutput writer = null; try { writer = new ObjectOutputStream(new FileOutputStream(path)); writer.writeInt(datArrLen()); writer.writeInt(datItemSize()); for (Item item : dat) { if (item == null) { continue; } writer.writeObject(item); } } finally { if (writer != null) { writer.flush(); writer.close(); } } }
output.flush(); byte[] body = outputStream.toByteArray();
output.flush();
output.flush();
/** Serialization/deserialization. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { ClientConfiguration target = new ClientConfiguration() .setAddresses("127.0.0.1:10800", "127.0.0.1:10801") .setTimeout(123) .setBinaryConfiguration(new BinaryConfiguration() .setClassNames(Collections.singleton("Person")) ) .setSslMode(SslMode.REQUIRED) .setSslClientCertificateKeyStorePath("client.jks") .setSslClientCertificateKeyStoreType("JKS") .setSslClientCertificateKeyStorePassword("123456") .setSslTrustCertificateKeyStorePath("trust.jks") .setSslTrustCertificateKeyStoreType("JKS") .setSslTrustCertificateKeyStorePassword("123456") .setSslKeyAlgorithm("SunX509"); ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(outBytes); out.writeObject(target); out.flush(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(outBytes.toByteArray())); Object desTarget = in.readObject(); assertTrue(Comparers.equal(target, desTarget)); }
output.flush(); byte[] body = outputStream.toByteArray();