List of usage examples for java.io DataOutputStream writeByte
public final void writeByte(int v) throws IOException
byte
to the underlying output stream as a 1-byte value. From source file:Messenger.TorLib.java
/** * This method Creates a socket, then sends the inital SOCKS request info * It stops before reading so that other methods may * differently interpret the results. It returns the open socket. * * @param targetHostname The hostname of the destination host. * @param targetPort The port to connect to * @param req SOCKS/TOR request code//from w w w . ja va 2 s . c o m * @return An open Socket that has been sent the SOCK4a init codes. * @throws IOException from any Socket problems */ static Socket TorSocketPre(String targetHostname, int targetPort, byte req) throws IOException { Socket s; // System.out.println("Opening connection to "+targetHostname+":"+targetPort+ // " via proxy "+proxyAddr+":"+proxyPort+" of type "+req); s = new Socket(proxyAddr, proxyPort); DataOutputStream os = new DataOutputStream(s.getOutputStream()); os.writeByte(SOCKS_VERSION); os.writeByte(req); // 2 bytes os.writeShort(targetPort); // 4 bytes, high byte first os.writeInt(SOCKS4A_FAKEIP); os.writeByte(SOCKS_DELIM); os.writeBytes(targetHostname); os.writeByte(SOCKS_DELIM); return (s); }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static void serializeMetricInfo(DataOutputStream dos, QueryScopeInfo info) throws IOException { serializeString(dos, info.scope);/*from w w w. j a va 2 s .c om*/ dos.writeByte(info.getCategory()); switch (info.getCategory()) { case INFO_CATEGORY_JM: break; case INFO_CATEGORY_TM: String tmID = ((QueryScopeInfo.TaskManagerQueryScopeInfo) info).taskManagerID; serializeString(dos, tmID); break; case INFO_CATEGORY_JOB: QueryScopeInfo.JobQueryScopeInfo jobInfo = (QueryScopeInfo.JobQueryScopeInfo) info; serializeString(dos, jobInfo.jobID); break; case INFO_CATEGORY_TASK: QueryScopeInfo.TaskQueryScopeInfo taskInfo = (QueryScopeInfo.TaskQueryScopeInfo) info; serializeString(dos, taskInfo.jobID); serializeString(dos, taskInfo.vertexID); dos.writeInt(taskInfo.subtaskIndex); break; case INFO_CATEGORY_OPERATOR: QueryScopeInfo.OperatorQueryScopeInfo operatorInfo = (QueryScopeInfo.OperatorQueryScopeInfo) info; serializeString(dos, operatorInfo.jobID); serializeString(dos, operatorInfo.vertexID); dos.writeInt(operatorInfo.subtaskIndex); serializeString(dos, operatorInfo.operatorName); break; } }
From source file:org.activiti.engine.test.api.repository.diagram.ProcessDiagramRetrievalTest.java
/** * Might be used for debugging {@link ProcessDiagramRetrievalTest#testGetProcessDiagram()}. *///w ww. j a v a 2s.c o m @SuppressWarnings("unused") private static void writeToFile(InputStream is, File file) throws Exception { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); int c; while ((c = is.read()) != -1) { out.writeByte(c); } is.close(); out.close(); }
From source file:com.dbay.apns4j.tools.ApnsTools.java
public final static byte[] generateData(List<FrameItem> list) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(bos); int frameLength = 0; for (FrameItem item : list) { // itemId length = 1, itemDataLength = 2 frameLength += 1 + 2 + item.getItemLength(); }/*w w w . ja v a 2 s. c o m*/ try { os.writeByte(Command.SEND_V2); os.writeInt(frameLength); for (FrameItem item : list) { os.writeByte(item.getItemId()); os.writeShort(item.getItemLength()); os.write(item.getItemData()); } return bos.toByteArray(); } catch (IOException e) { e.printStackTrace(); } throw new RuntimeException(); }
From source file:nl.sidn.dnslib.message.util.DNSStringUtil.java
public static byte[] writeName(String name) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); try {/*from www. ja va 2s .co m*/ //write nameserver string String[] labels = StringUtils.split(name, "."); for (String label : labels) { //write label length dos.writeByte(label.length()); dos.write(label.getBytes()); } //write root with zero byte dos.writeByte(0); } catch (IOException e) { throw new RuntimeException("Error while wrting name", e); } return bos.toByteArray(); }
From source file:org.apache.hive.hcatalog.streaming.mutate.client.AcidTableSerializer.java
/** Returns a base 64 encoded representation of the supplied {@link AcidTable}. */ public static String encode(AcidTable table) throws IOException { DataOutputStream data = null; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try {/*from w w w .java 2 s.co m*/ data = new DataOutputStream(bytes); data.writeUTF(table.getDatabaseName()); data.writeUTF(table.getTableName()); data.writeBoolean(table.createPartitions()); if (table.getTransactionId() <= 0) { LOG.warn("Transaction ID <= 0. The recipient is probably expecting a transaction ID."); } data.writeLong(table.getTransactionId()); data.writeByte(table.getTableType().getId()); Table metaTable = table.getTable(); if (metaTable != null) { byte[] thrift = new TSerializer(new TCompactProtocol.Factory()).serialize(metaTable); data.writeInt(thrift.length); data.write(thrift); } else { LOG.warn("Meta store table is null. The recipient is probably expecting an instance."); data.writeInt(0); } } catch (TException e) { throw new IOException("Error serializing meta store table.", e); } finally { data.close(); } return PROLOG_V1 + new String(Base64.encodeBase64(bytes.toByteArray()), Charset.forName("UTF-8")); }
From source file:RealFunctionValidation.java
public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out, final Class<?> type) throws IOException { if (!type.isPrimitive()) { throw new IllegalArgumentException("type must be primitive"); }//w w w. j ava 2 s. co m if (type.equals(Boolean.TYPE)) { final boolean x = in.readBoolean(); out.writeBoolean(x); return Boolean.valueOf(x); } else if (type.equals(Byte.TYPE)) { final byte x = in.readByte(); out.writeByte(x); return Byte.valueOf(x); } else if (type.equals(Character.TYPE)) { final char x = in.readChar(); out.writeChar(x); return Character.valueOf(x); } else if (type.equals(Double.TYPE)) { final double x = in.readDouble(); out.writeDouble(x); return Double.valueOf(x); } else if (type.equals(Float.TYPE)) { final float x = in.readFloat(); out.writeFloat(x); return Float.valueOf(x); } else if (type.equals(Integer.TYPE)) { final int x = in.readInt(); out.writeInt(x); return Integer.valueOf(x); } else if (type.equals(Long.TYPE)) { final long x = in.readLong(); out.writeLong(x); return Long.valueOf(x); } else if (type.equals(Short.TYPE)) { final short x = in.readShort(); out.writeShort(x); return Short.valueOf(x); } else { // This should never occur. throw new IllegalStateException(); } }
From source file:com.ebay.nest.io.sede.lazy.LazyUtils.java
/** * Write out a binary representation of a PrimitiveObject to a byte stream. * * @param out ByteStream.Output, an unsynchronized version of ByteArrayOutputStream, used as a * backing buffer for the the DataOutputStream * @param o the PrimitiveObject//from ww w .ja v a 2s. c o m * @param oi the PrimitiveObjectInspector * @throws IOException on error during the write operation */ public static void writePrimitive(OutputStream out, Object o, PrimitiveObjectInspector oi) throws IOException { DataOutputStream dos = new DataOutputStream(out); try { switch (oi.getPrimitiveCategory()) { case BOOLEAN: boolean b = ((BooleanObjectInspector) oi).get(o); dos.writeBoolean(b); break; case BYTE: byte bt = ((ByteObjectInspector) oi).get(o); dos.writeByte(bt); break; case SHORT: short s = ((ShortObjectInspector) oi).get(o); dos.writeShort(s); break; case INT: int i = ((IntObjectInspector) oi).get(o); dos.writeInt(i); break; case LONG: long l = ((LongObjectInspector) oi).get(o); dos.writeLong(l); break; case FLOAT: float f = ((FloatObjectInspector) oi).get(o); dos.writeFloat(f); break; case DOUBLE: double d = ((DoubleObjectInspector) oi).get(o); dos.writeDouble(d); break; default: throw new RuntimeException("Hive internal error."); } } finally { // closing the underlying ByteStream should have no effect, the data should still be // accessible dos.close(); } }
From source file:org.apache.hadoop.hive.serde2.lazy.LazyUtils.java
/** * Write out a binary representation of a PrimitiveObject to a byte stream. * * @param out ByteStream.Output, an unsynchronized version of ByteArrayOutputStream, used as a * backing buffer for the the DataOutputStream * @param o the PrimitiveObject//from w w w.j a v a 2s .c o m * @param oi the PrimitiveObjectInspector * @throws IOException on error during the write operation */ public static void writePrimitive(OutputStream out, Object o, PrimitiveObjectInspector oi) throws IOException { DataOutputStream dos = new DataOutputStream(out); try { switch (oi.getPrimitiveCategory()) { case BOOLEAN: boolean b = ((BooleanObjectInspector) oi).get(o); dos.writeBoolean(b); break; case BYTE: byte bt = ((ByteObjectInspector) oi).get(o); dos.writeByte(bt); break; case SHORT: short s = ((ShortObjectInspector) oi).get(o); dos.writeShort(s); break; case INT: int i = ((IntObjectInspector) oi).get(o); dos.writeInt(i); break; case LONG: long l = ((LongObjectInspector) oi).get(o); dos.writeLong(l); break; case FLOAT: float f = ((FloatObjectInspector) oi).get(o); dos.writeFloat(f); break; case DOUBLE: double d = ((DoubleObjectInspector) oi).get(o); dos.writeDouble(d); break; case BINARY: { BytesWritable bw = ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); out.write(bw.getBytes(), 0, bw.getLength()); break; } default: throw new RuntimeException("Hive internal error."); } } finally { // closing the underlying ByteStream should have no effect, the data should still be // accessible dos.close(); } }
From source file:org.apache.fontbox.ttf.TTFSubFont.java
private static void writeUint8(DataOutputStream dos, int i) throws IOException { dos.writeByte(i); }