public void writeClass(OutputStream is) throws IOException { DataOutputStream classStream = new DataOutputStream(is); classStream.writeInt(magic); classStream.writeShort(minorVersion); classStream.writeShort(majorVersion); classStream.writeShort(constantPool.size()); Iterator<CPInfo> i = constantPool.iterator(); i.next(); // Skip initial, not really there entry for (; i.hasNext(); ) { CPInfo poolEntry = i.next(); poolEntry.write(classStream); // Constant pool array must have null entry after long or double if (poolEntry.tag == CONSTANT_Double || poolEntry.tag == CONSTANT_Long) i.next(); } classStream.writeShort(accessFlags); classStream.writeShort(thisClassIndex); classStream.writeShort(superClassIndex); classStream.writeShort(interfaces.size()); for (Iterator<Integer> j = interfaces.iterator(); j.hasNext(); ) { classStream.writeShort(j.next()); } classStream.writeShort(fields.size()); for (Iterator<FieldInfo> j = fields.iterator(); j.hasNext(); ) { j.next().write(classStream); } classStream.writeShort(methods.size()); for (Iterator<MethodInfo> j = methods.iterator(); j.hasNext(); ) { j.next().write(classStream); } attributes.write(classStream); }
/** * @exception IOException * @exception DicomException */ public CEchoRequestCommandMessage() throws DicomException, IOException { commandField = MessageServiceElementCommand.C_ECHO_RQ; messageID = super.getNextAvailableMessageID(); int dataSetType = 0x0101; // none // NB. The Affected SOP Class UID should have no extra trailing padding, otherwise the // SCP may fail and send an A-ABORT :) (Part 5 says one null (not space) is allowed) // This is taken care of by the Attribute.write() AttributeList list = new AttributeList(); { AttributeTag t = groupLengthTag; Attribute a = new UnsignedLongAttribute(t); a.addValue(0); list.put(t, a); } { AttributeTag t = TagFromName.AffectedSOPClassUID; Attribute a = new UniqueIdentifierAttribute(t); a.addValue(SOPClass.Verification); list.put(t, a); } { AttributeTag t = TagFromName.CommandField; Attribute a = new UnsignedShortAttribute(t); a.addValue(commandField); list.put(t, a); } { AttributeTag t = TagFromName.MessageID; Attribute a = new UnsignedShortAttribute(t); a.addValue(messageID); list.put(t, a); } { AttributeTag t = TagFromName.CommandDataSetType; Attribute a = new UnsignedShortAttribute(t); a.addValue(dataSetType); list.put(t, a); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); DicomOutputStream dout = new DicomOutputStream( bout, null /* no meta-header */, TransferSyntax.ImplicitVRLittleEndian); list.write(dout); bytes = bout.toByteArray(); groupLength = bytes.length - 12; bytes[8] = (byte) groupLength; // little endian bytes[9] = (byte) (groupLength >> 8); bytes[10] = (byte) (groupLength >> 16); bytes[11] = (byte) (groupLength >> 24); // System.err.println("CEchoRequestCommandMessage: bytes="+HexDump.dump(bytes)); }
/** * Read a DICOM dataset and write an XML representation of it to the standard output, or vice * versa. * * @param arg either one filename of the file containing the DICOM dataset, or a direction * argument (toDICOM or toXML, case insensitive) and an input filename */ public static void main(String arg[]) { try { boolean bad = true; boolean toXML = true; String filename = null; if (arg.length == 1) { bad = false; toXML = true; filename = arg[0]; } else if (arg.length == 2) { filename = arg[1]; if (arg[0].toLowerCase(java.util.Locale.US).equals("toxml")) { bad = false; toXML = true; } else if (arg[0].toLowerCase(java.util.Locale.US).equals("todicom") || arg[0].toLowerCase(java.util.Locale.US).equals("todcm")) { bad = false; toXML = false; } } if (bad) { System.err.println( "usage: XMLRepresentationOfDicomObjectFactory [toDICOM|toXML] inputfile"); } else { if (toXML) { AttributeList list = new AttributeList(); // System.err.println("reading list"); list.read(filename, null, true, true); // System.err.println("making document"); Document document = new XMLRepresentationOfDicomObjectFactory().getDocument(list); // System.err.println(toString(document)); write(System.out, document); } else { // long startReadTime = System.currentTimeMillis(); AttributeList list = new XMLRepresentationOfDicomObjectFactory().getAttributeList(filename); // System.err.println("AttributeList.main(): read XML and create DICOM AttributeList - // done in "+(System.currentTimeMillis()-startReadTime)+" ms"); String sourceApplicationEntityTitle = Attribute.getSingleStringValueOrEmptyString( list, TagFromName.SourceApplicationEntityTitle); list.removeMetaInformationHeaderAttributes(); FileMetaInformation.addFileMetaInformation( list, TransferSyntax.ExplicitVRLittleEndian, sourceApplicationEntityTitle); list.write( System.out, TransferSyntax.ExplicitVRLittleEndian, true /*useMeta*/, true /*useBufferedStream*/); } } } catch (Exception e) { e.printStackTrace(System.err); } }