@Override public void flushBuffer() throws IOException { output.flush(); }
@Override public void flushBuffer() throws IOException { output.flush(); }
public byte[] execute(Kryo kryo) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Output output = new Output(byteArrayOutputStream); kryo.writeClassAndObject(output, object); output.flush(); return byteArrayOutputStream.toByteArray(); } });
@Override public void handleDataPoints(TaskInfo taskInfo, Collection<DataPoint> dataPoints) { try { HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); try (Output out = new Output(con.getOutputStream())) { serializer.serializeInto(Arrays.asList(taskInfo, dataPoints, topologyId), out); out.flush(); } //The connection is not sent unless a response is requested int response = con.getResponseCode(); } catch (Exception e) { throw new RuntimeException(e); } }
private void safeWriteToOutput(Output output, BaseProtocol.JobResult<?> jobResult) throws IOException { ByteArrayOutputStream boas = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(boas); oos.writeObject(jobResult); oos.flush(); output.write(boas.toByteArray()); output.flush(); }
@Override public void writeTo(final Object object, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { final Output output = new Output(entityStream); kryoPool.run(new KryoCallback() { public Object execute(Kryo kryo) { kryo.writeObject(output, object); return null; } }); output.flush(); }
public static <T> byte[] writeToByteArray(T obj) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Output output = new Output(byteArrayOutputStream); Kryo kryo = getInstance(); kryo.writeClassAndObject(output, obj); output.flush(); return byteArrayOutputStream.toByteArray(); }
public static <T> byte[] writeToByteArray(T obj) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Output output = new Output(byteArrayOutputStream); Kryo kryo = getInstance(); kryo.writeClassAndObject(output, obj); output.flush(); return byteArrayOutputStream.toByteArray(); }
private byte[] getKryoSerializedBytes (final Object obj) { final Kryo kryo = new Kryo(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); final Output output = new Output(os); kryo.setInstantiatorStrategy(new StdInstantiatorStrategy()); kryo.writeClassAndObject(output, obj); output.flush(); return os.toByteArray(); }
@Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf buf) throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); Output kryoOut = new Output(bytes); kryos.get().writeClassAndObject(kryoOut, msg); kryoOut.flush(); byte[] msgData = maybeEncrypt(bytes.toByteArray()); LOG.trace("Encoded message of type {} ({} bytes)", msg.getClass().getName(), msgData.length); checkSize(msgData.length); buf.ensureWritable(msgData.length + 4); buf.writeInt(msgData.length); buf.writeBytes(msgData); }
@Override public byte[] serialize(final Object obj) throws TransactionException { byte[] bytes; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) { //获取kryo对象 Kryo kryo = new Kryo(); kryo.writeObject(output, obj); bytes = output.toBytes(); output.flush(); } catch (IOException ex) { throw new TransactionException("kryo serialize error" + ex.getMessage()); } return bytes; }
/** {@inheritDoc} */ @Override public ByteBuffer serialize(Object obj) { if (obj == null) return null; ByteArrayOutputStream stream = null; Output out = null; try { stream = new ByteArrayOutputStream(DFLT_BUFFER_SIZE); out = new Output(stream); kryos.get().writeClassAndObject(out, obj); out.flush(); return ByteBuffer.wrap(stream.toByteArray()); } catch (Throwable e) { throw new IllegalStateException("Failed to serialize object of the class '" + obj.getClass().getName() + "'", e); } finally { U.closeQuiet(out); U.closeQuiet(stream); } }
@Override public byte[] serialize(final Object obj) throws MythException { byte[] bytes; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) { //获取kryo对象 Kryo kryo = new Kryo(); kryo.writeObject(output, obj); bytes = output.toBytes(); output.flush(); } catch (IOException ex) { throw new MythException("kryo serialize error" + ex.getMessage()); } return bytes; }
/** * 序列化. * * @param obj 需要序更列化的对象 * @return 序列化后的byte 数组 * @throws HmilyException 异常 */ @Override public byte[] serialize(final Object obj) throws HmilyException { byte[] bytes; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Output output = new Output(outputStream)) { //获取kryo对象 Kryo kryo = new Kryo(); kryo.writeObject(output, obj); bytes = output.toBytes(); output.flush(); } catch (IOException ex) { throw new HmilyException("kryo serialize error" + ex.getMessage()); } return bytes; }
public static byte[] serialize(final Kryo kryo, final Object o) { if (o == null) { throw new NullPointerException("Can't serialize null"); } final Output output = new Output(4096); kryo.writeObject(output, o); output.flush(); return output.getBuffer(); }
output.flush();
private ByteBuffer getSerializedSargForMetastore(boolean isOriginal) { if (sarg == null) { return null; } ByteBuffer serializedSarg = isOriginal ? sargIsOriginal : sargNotIsOriginal; if (serializedSarg != null) { return serializedSarg; } SearchArgument sarg2 = sarg; Kryo kryo = SerializationUtilities.borrowKryo(); try { if ((isOriginal ? sargNotIsOriginal : sargIsOriginal) == null) { sarg2 = kryo.copy(sarg2); // In case we need it for the other case. } translateSargToTableColIndexes(sarg2, conf, OrcInputFormat.getRootColumn(isOriginal)); ExternalCache.Baos baos = new Baos(); Output output = new Output(baos); kryo.writeObject(output, sarg2); output.flush(); serializedSarg = baos.get(); if (isOriginal) { sargIsOriginal = serializedSarg; } else { sargNotIsOriginal = serializedSarg; } } finally { SerializationUtilities.releaseKryo(kryo); } return serializedSarg; }
@Override public void flush() { unshadedOutput.flush(); } }
@Override public void writeClassAndObject(final Object object, OutputStream outputStream) { Kryo k = null; try { k = KRYOS.take(); final Output kryoOutput = new Output(outputStream); k.writeClassAndObject(kryoOutput, object); kryoOutput.flush(); } catch (final InterruptedException e) { throw new IllegalStateException(e); } finally { try { KRYOS.put(k); } catch (final InterruptedException e) { throw new IllegalStateException(e); } } }
@Override public byte[] serialize(final Object obj) { byte[] bytes; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { //获取kryo对象 Kryo kryo = new Kryo(); Output output = new Output(outputStream); kryo.writeClassAndObject(output, obj); bytes = output.toBytes(); output.flush(); } catch (IOException ex) { throw new SerializerException("kryo serialize error" + ex.getMessage()); } return bytes; }