public DicomDirWriter(File file, FileSetInformation fileSetInfo) throws IOException { super(new RandomAccessFile(file, "rw"), fileSetInfo); this.file = file; // ensure fileSetInfo represents empty file-set fileSetInfo.setOffsetFirstRootRecord(0); fileSetInfo.setOffsetLastRootRecord(0); raf.setLength(0); out = new DicomOutputStream(raf); out.setExplicitSequenceLength(true); out.setExplicitItemLength(true); out.writeDicomFile(fileSetInfo.getDicomObject()); out.writeHeader(Tag.DirectoryRecordSequence, VR.SQ, 0); this.firstRecordPos = (int) out.getStreamPosition(); this.recordSeqLen = 0; }
public void writeTo(PDVOutputStream out, String tsuid) throws IOException { DicomOutputStream dos = new DicomOutputStream(out); dos.writeDataset(data, TransferSyntax.valueOf(tsuid)); }
/** * Write a DICOM dataset to the output stream. * * @param attrs * A DicomObject containing the attributes to write. * @param transferSyntax * A TransferSyntax object representing the transfer syntax of * the file. * @throws IOException */ public void writeDataset(DicomObject attrs, TransferSyntax transferSyntax) throws IOException { setTransferSyntax(transferSyntax); this.ts = transferSyntax; writeElements(attrs.datasetIterator(), includeGroupLength, createItemInfo(attrs)); if (autoFinish) { finish(); } }
private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); DicomOutputStream dos = new DicomOutputStream((OutputStream) s); dos.serializeDicomObject(attrs); }
/** * Write the given image as a byte array to the sequence. */ public void writeBytesToSequence(byte[] data, ImageWriteParam param) throws IOException { if (encapsulated) { dos.writeHeader(Tag.Item, null, (data.length+1) & ~1); } dos.write(data); if ((data.length & 1) != 0) dos.write(0); // The flush allows any memory buffer to be cleared. dos.flush(); ((ImageOutputStream) output).flush(); }
public void writeFileMetaInformation(DicomObject attrs) throws IOException { if (preamble != null) { write(preamble, 0, PREAMBLE_LENGTH); write('D'); write('I'); write('C'); write('M'); } this.ts = TransferSyntax.ExplicitVRLittleEndian; writeElements(attrs.fileMetaInfoIterator(), true, new ItemInfo(attrs .fileMetaInfoIterator(), true)); }
DicomObject dobj = dmeta.getDicomObject(); Object output = getOutput(); dos = new DicomOutputStream((ImageOutputStream) output); dos.setAutoFinish(false); if( dmeta.isFileMetaInfoIncluded() ) { dos.writeDicomFile(dobj); } else { dos.writeDataset(dobj, dobj.getString(Tag.TransferSyntaxUID)); dos.writeHeader(Tag.PixelData, VR.OB, -1); dos.writeHeader(Tag.Item, null, 0); } else { int frames = dobj.getInt(Tag.NumberOfFrames, 1); dos.writeHeader(Tag.PixelData, vr, pixelDataLength); dos.flush(); ((ImageOutputStream) output).flush();
dis.close(); DicomOutputStream dos = new DicomOutputStream(out); attrs.putString(Tag.RetrieveURI, VR.UT, info.f.toURI().toString()); dos.writeDataset(attrs, tsuid); } else { DicomInputStream dis = null; DicomOutputStream dos = new DicomOutputStream(out); dos.setTransferSyntax(tsuid); TranscoderInputHandler h = new TranscoderInputHandler(dos, transcoderBufferSize);
private void transcodeAttribute(DicomInputStream in) throws IOException { final int tag = in.tag(); final VR vr = in.vr(); final int vallen = in.valueLength(); final DicomObject attrs = in.getDicomObject(); if (vallen == -1 || vr == VR.SQ) { out.writeHeader(tag, vr, -1); TransferSyntax prevTS = out.getTransferSyntax(); if (vr == VR.UN) { out.setTransferSyntax(TransferSyntax.ImplicitVRLittleEndian); } in.readValue(in); attrs.remove(tag); out.writeHeader(Tag.SequenceDelimitationItem, null, 0); out.setTransferSyntax(prevTS); } else if (!TagUtils.isGroupLengthElement(tag)) { out.writeHeader(tag, vr, vallen); if (tag == Tag.SpecificCharacterSet || TagUtils.isPrivateCreatorDataElement(tag)) { byte[] val = in.readBytes(vallen); boolean bigEndian = in.getTransferSyntax().bigEndian(); attrs.putBytes(tag, vr, val, bigEndian); out.write(val); } else { transcodeValue(in, vr); } } }
public DicomDirWriter(File file) throws IOException { super(new RandomAccessFile(checkExists(file), "rw")); this.file = file; offsetFirstRootRecord(filesetInfo.getOffsetFirstRootRecord()); offsetLastRootRecord(filesetInfo.getOffsetLastRootRecord()); this.firstRecordPos = in.getStreamPosition(); this.recordSeqLen = in.valueLength(); out = new DicomOutputStream(raf); out.setExplicitSequenceLength(recordSeqLen != -1); out.setExplicitItemLength(recordSeqLen != -1); if (filesetInfo.isEmpty()) { this.recordSeqLen = 0; } }
gggg0 = gggg; assert itemInfo != null; writeGroupLength(gggg, itemInfo.grlen[++gri]); writeHeader(a.tag(), vr, len); a.bigEndian(ts.bigEndian()); if (a.hasItems()) { .removeFirst() : null; writeItem(item, childItemInfo); for (int i = 0, n = a.countItems(); i < n; i++) { byte[] val = a.getFragment(i); writeHeader(Tag.Item, null, (val.length + 1) & ~1); write(val); if ((val.length & 1) != 0) write(0); write(val); if ((val.length & 1) != 0) write(vr.padding()); writeHeader(Tag.SequenceDelimitationItem, null, 0);
DicomOutputStream cmdout = new DicomOutputStream(this); cmdout.writeCommand(cmd); cmdout.close(); if (dataWriter != null)
public void writePostPixeldata(DicomObject dobj, String transferSyntax) throws IOException{ dos.writeDataset(dobj, transferSyntax); dos.flush(); finishStream(); }
/** * Write a DICOM object to the output stream using the specified * <code>DicomObject</code> to obtain the transfer syntax UID and other * attributes. * * @param attrs * The <code>DicomObject</code> containing the DICOM tags to * write into the file. * @throws IOException */ public void writeDicomFile(DicomObject attrs) throws IOException { String tsuid = attrs.getString(Tag.TransferSyntaxUID); if (tsuid == null) throw new IllegalArgumentException( "Missing (0002,0010) Transfer Syntax UID"); writeFileMetaInformation(attrs); writeDataset(attrs, tsuid); }
private void writeGroupLength(int tag, int length) throws IOException { writeHeader(tag, VR.UL, 4); write(VR.UL.toBytes(length, ts.bigEndian()), 0, 4); }
/** * Write a DICOM dataset to the output stream. * * @param attrs * A DicomObject containing the attributes to write. * @param tsuid * A String containing the transfer syntax UID of the file. * @throws IOException */ public void writeDataset(DicomObject attrs, String tsuid) throws IOException { writeDataset(attrs, TransferSyntax.valueOf(tsuid)); }
private void transcodeValue(DicomInputStream in, VR vr) throws IOException { boolean toggleEndian = out.getTransferSyntax().bigEndian() != in.getTransferSyntax().bigEndian(); int remaining = in.valueLength(); while (remaining > 0) { int len = Math.min(remaining, buf.length); in.readFully(buf, 0, len); if (toggleEndian) vr.toggleEndian(buf, 0, len); out.write(buf, 0, len); remaining -= len; } }
/** * Only for internal use by {@link org.dcm4che2.data.DicomObjectSerializer}. */ public void serializeDicomObject(DicomObject attrs) throws IOException { this.ts = TransferSyntax.ExplicitVRLittleEndian; writeElements(attrs.iterator(), false, null); writeHeader(Tag.ItemDelimitationItem, null, 0); }
public synchronized void rollback() throws IOException { filesetInfo.setOffsetFirstRootRecord(offsetFirstRootRecord()); filesetInfo.setOffsetLastRootRecord(offsetLastRootRecord()); cache.clear(); cachedParentRecord = null; cachedLastChildRecord = null; dirtyRecords.clear(); if (rollbackLen != -1) { recordSeqLen = rollbackLen - firstRecordPos; raf.seek(rollbackLen); if (!out.isExplicitSequenceLength() && !isEmpty()) { out.writeHeader(Tag.SequenceDelimitationItem, null, 0); } raf.setLength(raf.getFilePointer()); rollbackLen = -1; raf.seek(firstRecordPos - 14); raf.writeShort(FileSetInformation.NO_KNOWN_INCONSISTENCIES); filesetInfo.setFileSetConsistencyFlag( FileSetInformation.NO_KNOWN_INCONSISTENCIES); } }
public void endWriteSequence(boolean finish) throws IOException { if (encapsulated){ dos.writeHeader(Tag.SequenceDelimitationItem, null, 0); } if (finish) { finishStream(); } }