Java Code Examples for java.io.DataOutputStream#writeShort()
The following examples show how to use
java.io.DataOutputStream#writeShort() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyGenerator.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Generate code to push a constant integer value on to the operand * stack, using the "iconst_<i>", "bipush", or "sipush" instructions * depending on the size of the value. The code is written to the * supplied stream. */ private void code_ipush(int value, DataOutputStream out) throws IOException { if (value >= -1 && value <= 5) { out.writeByte(opc_iconst_0 + value); } else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) { out.writeByte(opc_bipush); out.writeByte(value & 0xFF); } else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) { out.writeByte(opc_sipush); out.writeShort(value & 0xFFFF); } else { throw new AssertionError(); } }
Example 2
Source File: ASTORE.java From awacs with Apache License 2.0 | 6 votes |
public void writeToStream(DataOutputStream out, int offset) throws IOException { int index = getOperand(0); if (index > 3) { if (wide) { out.writeByte(opc_wide); } out.writeByte(opc_astore); if (wide) { out.writeShort(index); } else { out.writeByte(index); } } else { out.writeByte(opcodes[index]); } }
Example 3
Source File: BinaryAttribute.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
static void write(BinaryAttribute attributes, DataOutputStream out, BinaryConstantPool cpool, Environment env) throws IOException { // count the number of attributes int attributeCount = 0; for (BinaryAttribute att = attributes; att != null; att = att.next) attributeCount++; out.writeShort(attributeCount); // write out each attribute for (BinaryAttribute att = attributes; att != null; att = att.next) { Identifier name = att.name; byte data[] = att.data; // write the identifier out.writeShort(cpool.indexString(name.toString(), env)); // write the length out.writeInt(data.length); // write the data out.write(data, 0, data.length); } }
Example 4
Source File: AiffFileReader.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** write_ieee_extended(DataOutputStream dos, double f) throws IOException { * Extended precision IEEE floating-point conversion routine. * @argument DataOutputStream * @argument double * @return void * @exception IOException */ private void write_ieee_extended(DataOutputStream dos, double f) throws IOException { int exponent = 16398; double highMantissa = f; // For now write the integer portion of f // $$jb: 03.30.99: stay in synch with JMF on this!!!! while (highMantissa < 44000) { highMantissa *= 2; exponent--; } dos.writeShort(exponent); dos.writeInt( ((int) highMantissa) << 16); dos.writeInt(0); // low Mantissa }
Example 5
Source File: ProxyGenerator.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void write(DataOutputStream out) throws IOException { /* * Write all the items of the "field_info" structure. * See JVMS section 4.5. */ // u2 access_flags; out.writeShort(accessFlags); // u2 name_index; out.writeShort(cp.getUtf8(name)); // u2 descriptor_index; out.writeShort(cp.getUtf8(descriptor)); // u2 attributes_count; out.writeShort(0); // (no field_info attributes for proxy classes) }
Example 6
Source File: ProxyGenerator.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
/** * Generate code to invoke the Class.forName with the name of the given * class to get its Class object at runtime. The code is written to * the supplied stream. Note that the code generated by this method * may caused the checked ClassNotFoundException to be thrown. */ private void codeClassForName(Class cl, DataOutputStream out) throws IOException { code_ldc(cp.getString(cl.getName()), out); out.writeByte(opc_invokestatic); out.writeShort(cp.getMethodRef( "java/lang/Class", "forName", "(Ljava/lang/String;)Ljava/lang/Class;")); }
Example 7
Source File: MULTIANEWARRAY.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Dump instruction as byte code to stream out. * @param out Output stream */ @Override public void dump( final DataOutputStream out ) throws IOException { out.writeByte(super.getOpcode()); out.writeShort(super.getIndex()); out.writeByte(dimensions); }
Example 8
Source File: ConstPool.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
@Override public void write(DataOutputStream out) throws IOException { out.writeByte(tag); out.writeShort(bootstrap); out.writeShort(nameAndType); }
Example 9
Source File: ProxyServerHelper.java From codenameone-demos with GNU General Public License v2.0 | 5 votes |
/** * Returns an OK response to the client * @param resp the response object * @param def the method definition * @param response the result from the method */ public static void writeResponse(HttpServletResponse resp, WSDefinition def, short response) throws IOException { resp.setStatus(HttpServletResponse.SC_OK); DataOutputStream dos = new DataOutputStream(resp.getOutputStream()); dos.writeShort(response); dos.close(); }
Example 10
Source File: LocationServices.java From AIMSICDL with GNU General Public License v3.0 | 5 votes |
private static void writeData(OutputStream out, int cid, int lac, int mnc, int mcc) throws IOException { DataOutputStream dataOutputStream = new DataOutputStream(out); dataOutputStream.writeShort(0x0E); // Fct code dataOutputStream.writeInt(0); // requesting 8 byte session dataOutputStream.writeInt(0); dataOutputStream.writeShort(0); // country code string dataOutputStream.writeShort(0); // client descriptor string dataOutputStream.writeShort(0); // version tag string dataOutputStream.writeByte(0x1B); // Fct code dataOutputStream.writeInt(0); // MNC? dataOutputStream.writeInt(0); // MCC? dataOutputStream.writeInt(3); // RAT = Radio Access Type (3=GSM, 5=UMTS) dataOutputStream.writeShort(0); // length of provider name // provider name string dataOutputStream.writeInt(cid); // CID dataOutputStream.writeInt(lac); // LAC dataOutputStream.writeInt(mnc); // MNC dataOutputStream.writeInt(mcc); // MCC dataOutputStream.writeInt(-1); // always -1 dataOutputStream.writeInt(0); // rx level dataOutputStream.flush(); }
Example 11
Source File: StackMap.java From commons-bcel with Apache License 2.0 | 5 votes |
/** * Dump stack map table attribute to file stream in binary format. * * @param file Output file stream * @throws IOException */ @Override public void dump( final DataOutputStream file ) throws IOException { super.dump(file); file.writeShort(map.length); for (final StackMapEntry entry : map) { entry.dump(file); } }
Example 12
Source File: ProxyGenerator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Generate code for wrapping an argument of the given type * whose value can be found at the specified local variable * index, in order for it to be passed (as an Object) to the * invocation handler's "invoke" method. The code is written * to the supplied stream. */ private void codeWrapArgument(Class<?> type, int slot, DataOutputStream out) throws IOException { if (type.isPrimitive()) { PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(type); if (type == int.class || type == boolean.class || type == byte.class || type == char.class || type == short.class) { code_iload(slot, out); } else if (type == long.class) { code_lload(slot, out); } else if (type == float.class) { code_fload(slot, out); } else if (type == double.class) { code_dload(slot, out); } else { throw new AssertionError(); } out.writeByte(opc_invokestatic); out.writeShort(cp.getMethodRef( prim.wrapperClassName, "valueOf", prim.wrapperValueOfDesc)); } else { code_aload(slot, out); } }
Example 13
Source File: ProxyGenerator.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Write this constant pool to a stream as part of * the class file format. * * This consists of writing the "constant_pool_count" and * "constant_pool[]" items of the "ClassFile" structure, as * described in JVMS section 4.1. */ public void write(OutputStream out) throws IOException { DataOutputStream dataOut = new DataOutputStream(out); // constant_pool_count: number of entries plus one dataOut.writeShort(pool.size() + 1); for (Entry e : pool) { e.write(dataOut); } }
Example 14
Source File: ClassFile.java From HotswapAgent with GNU General Public License v2.0 | 5 votes |
/** * Writes a class file represented by this object into an output stream. */ public void write(DataOutputStream out) throws IOException { int i, n; out.writeInt(0xCAFEBABE); // magic out.writeShort(minor); // minor version out.writeShort(major); // major version constPool.write(out); // constant pool out.writeShort(accessFlags); out.writeShort(thisClass); out.writeShort(superClass); if (interfaces == null) n = 0; else n = interfaces.length; out.writeShort(n); for (i = 0; i < n; ++i) out.writeShort(interfaces[i]); n = fields.size(); out.writeShort(n); for (i = 0; i < n; ++i) { FieldInfo finfo = fields.get(i); finfo.write(out); } out.writeShort(methods.size()); for (MethodInfo minfo:methods) minfo.write(out); out.writeShort(attributes.size()); AttributeInfo.writeAll(attributes, out); }
Example 15
Source File: ProxyGenerator.java From javaide with GNU General Public License v3.0 | 4 votes |
/** * Generate code for initializing the static field that stores * the Method object for this proxy method. The code is written * to the supplied stream. */ private void codeFieldInitialization(DataOutputStream out) throws IOException { codeClassForName(fromClass, out); code_ldc(cp.getString(methodName), out); code_ipush(parameterTypes.length, out); out.writeByte(opc_anewarray); out.writeShort(cp.getClass("java/lang/Class")); for (int i = 0; i < parameterTypes.length; i++) { out.writeByte(opc_dup); code_ipush(i, out); if (parameterTypes[i].isPrimitive()) { PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(parameterTypes[i]); out.writeByte(opc_getstatic); out.writeShort(cp.getFieldRef( prim.wrapperClassName, "TYPE", "Ljava/lang/Class;")); } else { codeClassForName(parameterTypes[i], out); } out.writeByte(opc_aastore); } out.writeByte(opc_invokevirtual); out.writeShort(cp.getMethodRef( "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)" + "Ljava/lang/reflect/Method;")); out.writeByte(opc_putstatic); out.writeShort(cp.getFieldRef( dotToSlash(className), methodFieldName, "Ljava/lang/reflect/Method;")); }
Example 16
Source File: DynClass.java From jblink with BSD 3-Clause "New" or "Revised" License | 4 votes |
void write (DataOutputStream os) throws IOException { os.write (opc); os.writeShort ((short)ref); }
Example 17
Source File: ProxyGenerator.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Generate code for initializing the static field that stores * the Method object for this proxy method. The code is written * to the supplied stream. */ private void codeFieldInitialization(DataOutputStream out) throws IOException { codeClassForName(fromClass, out); code_ldc(cp.getString(methodName), out); code_ipush(parameterTypes.length, out); out.writeByte(opc_anewarray); out.writeShort(cp.getClass("java/lang/Class")); for (int i = 0; i < parameterTypes.length; i++) { out.writeByte(opc_dup); code_ipush(i, out); if (parameterTypes[i].isPrimitive()) { PrimitiveTypeInfo prim = PrimitiveTypeInfo.get(parameterTypes[i]); out.writeByte(opc_getstatic); out.writeShort(cp.getFieldRef( prim.wrapperClassName, "TYPE", "Ljava/lang/Class;")); } else { codeClassForName(parameterTypes[i], out); } out.writeByte(opc_aastore); } out.writeByte(opc_invokevirtual); out.writeShort(cp.getMethodRef( "java/lang/Class", "getMethod", "(Ljava/lang/String;[Ljava/lang/Class;)" + "Ljava/lang/reflect/Method;")); out.writeByte(opc_putstatic); out.writeShort(cp.getFieldRef( dotToSlash(className), methodFieldName, "Ljava/lang/reflect/Method;")); }
Example 18
Source File: INVOKESTATIC.java From JByteMod-Beta with GNU General Public License v2.0 | 4 votes |
public void writeToStream(DataOutputStream out, int offset) throws IOException { out.writeByte(opc_invokestatic); out.writeShort(getOperand(0)); }
Example 19
Source File: StringSharingPlugin.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("fallthrough") private byte[] optimize(ResourcePoolEntry resource, ResourcePoolBuilder resources, StringTable strings, Set<Integer> descriptorIndexes, byte[] content) throws Exception { DataInputStream stream = new DataInputStream(new ByteArrayInputStream(content)); ByteArrayOutputStream outStream = new ByteArrayOutputStream(content.length); DataOutputStream out = new DataOutputStream(outStream); byte[] header = new byte[8]; //magic/4, minor/2, major/2 stream.readFully(header); out.write(header); int count = stream.readUnsignedShort(); out.writeShort(count); for (int i = 1; i < count; i++) { int tag = stream.readUnsignedByte(); byte[] arr; switch (tag) { case ConstantPool.CONSTANT_Utf8: { String original = stream.readUTF(); // 2 cases, a Descriptor or a simple String if (descriptorIndexes.contains(i)) { SignatureParser.ParseResult parseResult = SignatureParser.parseSignatureDescriptor(original); List<Integer> indexes = parseResult.types.stream().map((type) -> { return strings.addString(type); }).collect(Collectors.toList()); if (!indexes.isEmpty()) { out.write(StringSharingDecompressor.EXTERNALIZED_STRING_DESCRIPTOR); int sigIndex = strings.addString(parseResult.formatted); byte[] compressed = CompressIndexes.compress(sigIndex); out.write(compressed, 0, compressed.length); writeDescriptorReference(out, indexes); continue; } } // Put all strings in strings table. writeUTF8Reference(out, strings.addString(original)); break; } case ConstantPool.CONSTANT_Long: case ConstantPool.CONSTANT_Double: { i++; } default: { out.write(tag); int size = SIZES[tag]; arr = new byte[size]; stream.readFully(arr); out.write(arr); } } } out.write(content, content.length - stream.available(), stream.available()); out.flush(); return outStream.toByteArray(); }
Example 20
Source File: INVOKEDYNAMIC.java From awacs with Apache License 2.0 | 4 votes |
public void writeToStream(DataOutputStream out, int offset) throws IOException { out.writeByte(opc_invokedynamic); out.writeShort(getOperand(0)); out.writeByte(0); out.writeByte(0); }