/** * @param cap Capacisty * @return Writer. */ protected BinaryWriterExImpl createWriter(int cap) { return new BinaryWriterExImpl(null, new BinaryHeapOutputStream(cap), null, null); }
/** Serialize string. */ private void writeString(String s, BinaryOutputStream out) { try (BinaryRawWriterEx w = new BinaryWriterExImpl(marsh.context(), out, null, null)) { w.writeString(s); } }
/** * Gets writer for the given output stream. * * @param out Output stream. * @return Writer. */ public BinaryWriterExImpl writer(BinaryOutputStream out) { return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null); }
/** {@inheritDoc} */ @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException { if (obj == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null); writer.failIfUnregistered(failIfUnregistered); writer.marshal(obj); } }
/** Serialize String for thin client protocol. */ private static byte[] marshalString(String s) { try (BinaryOutputStream out = new BinaryHeapOutputStream(s == null ? 1 : s.length() + 20); BinaryRawWriterEx writer = new BinaryWriterExImpl(null, out, null, null) ) { writer.writeString(s); return out.arrayCopy(); } }
/** * @param obj Object to marshal. * @param failIfUnregistered Throw exception if class isn't registered. * @return Byte array. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ public byte[] marshal(@Nullable Object obj, boolean failIfUnregistered) throws BinaryObjectException { if (obj == null) return new byte[] { NULL }; try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { writer.failIfUnregistered(failIfUnregistered); writer.marshal(obj); return writer.array(); } }
/** * Create new writer with same context. * * @param typeId type * @return New writer. */ public BinaryWriterExImpl newWriter(int typeId) { BinaryWriterExImpl res = new BinaryWriterExImpl(ctx, out, schema, handles()); res.failIfUnregistered(failIfUnregistered); res.typeId(typeId); return res; }
/** * Write object. * * @param obj Object. * @throws org.apache.ignite.binary.BinaryObjectException In case of error. */ public void doWriteObject(@Nullable Object obj) throws BinaryObjectException { if (obj == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, handles()); writer.failIfUnregistered(failIfUnregistered); writer.marshal(obj); } }
/** {@inheritDoc} */ @Override public BinaryObject build() { try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) { Thread curThread = Thread.currentThread(); if (curThread instanceof IgniteThread) writer.failIfUnregistered(((IgniteThread)curThread).isForbiddenToRequestBinaryMetadata()); writer.typeId(typeId); BinaryBuilderSerializer serializationCtx = new BinaryBuilderSerializer(); serializationCtx.registerObjectWriting(this, 0); serializeTo(writer, serializationCtx); byte[] arr = writer.array(); return new BinaryObjectImpl(ctx, arr, 0); } }
/** * @param req Request. * @throws IOException In case of IO error. */ private void sendRequestRaw(JdbcRequest req) throws IOException { int cap = guessCapacity(req); BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(cap), null, null); req.writeBinary(writer, srvProtocolVer); synchronized (connMux) { send(writer.array()); } }
try (BinaryRawWriterEx w = new BinaryWriterExImpl(marsh.context(), out, null, null)) { w.writeInt(meta.typeId()); w.writeString(meta.typeName());
try (BinaryRawWriterEx writer = new BinaryWriterExImpl(marsh.context(), out, null, null)) { int origPos = out.position();
BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(HANDSHAKE_MSG_SIZE), null, null);
BinaryWriterExImpl writer = new BinaryWriterExImpl(marsh.context(), new BinaryHeapOutputStream(INIT_CAP), BinaryThreadLocalContext.get().schemaHolder(), null);
BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(HANDSHAKE_MSG_SIZE), null, null);
/** * @throws IgniteCheckedException If failed. */ @Test public void testThreadLocalArrayReleased() throws Exception { // Checking the writer directly. assertEquals(false, INSTANCE.isAcquired()); BinaryMarshaller marsh = binaryMarshaller(); try (BinaryWriterExImpl writer = new BinaryWriterExImpl(binaryContext(marsh))) { assertEquals(true, INSTANCE.isAcquired()); writer.writeString("Thread local test"); writer.array(); assertEquals(true, INSTANCE.isAcquired()); } // Checking the binary marshaller. assertEquals(false, INSTANCE.isAcquired()); marsh = binaryMarshaller(); marsh.marshal(new SimpleObject()); assertEquals(false, INSTANCE.isAcquired()); marsh = binaryMarshaller(); // Checking the builder. BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(binaryContext(marsh), "org.gridgain.foo.bar.TestClass"); builder.setField("a", "1"); BinaryObject binaryObj = builder.build(); assertEquals(false, INSTANCE.isAcquired()); }
BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(8), null, null);
/** * Gets writer for the given output stream. * * @param out Output stream. * @return Writer. */ public BinaryWriterExImpl writer(BinaryOutputStream out) { return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null); }
/** {@inheritDoc} */ @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException { if (obj == null) out.writeByte(GridBinaryMarshaller.NULL); else { BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null); writer.failIfUnregistered(failIfUnregistered); writer.marshal(obj); } }
/** * Create new writer with same context. * * @param typeId type * @return New writer. */ public BinaryWriterExImpl newWriter(int typeId) { BinaryWriterExImpl res = new BinaryWriterExImpl(ctx, out, schema, handles()); res.failIfUnregistered(failIfUnregistered); res.typeId(typeId); return res; }