public void endWriteSequence(boolean finish) throws IOException { if (encapsulated){ dos.writeHeader(Tag.SequenceDelimitationItem, null, 0); } if (finish) { finishStream(); } }
/** * 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); }
private void writeItem(DicomObject item, ItemInfo itemInfo) throws IOException { item.setItemOffset(pos); int len; if (item.isEmpty()) { len = explicitItemLengthIfZero ? 0 : -1; } else { len = explicitItemLength ? itemInfo.len : -1; } writeHeader(Tag.Item, null, len); writeElements(item.iterator(), includeGroupLength, itemInfo); if (len == -1) { writeHeader(Tag.ItemDelimitationItem, null, 0); } }
private void transcodeItem(DicomInputStream in) throws IOException { final DicomElement sq = in.sq(); final VR sqvr = sq.vr(); final int vallen = in.valueLength(); if (vallen == -1 || sqvr == VR.SQ) { out.writeHeader(Tag.Item, null, -1); in.readValue(in); out.writeHeader(Tag.ItemDelimitationItem, null, 0); } else { out.writeHeader(Tag.Item, null, in.valueLength()); transcodeValue(in, sqvr); } }
private void writeGroupLength(int tag, int length) throws IOException { writeHeader(tag, VR.UL, 4); write(VR.UL.toBytes(length, ts.bigEndian()), 0, 4); }
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); } }
/** * 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 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 synchronized void commit() throws IOException { if (rollbackLen != -1 && !out.isExplicitSequenceLength()) { raf.seek(endPos()); out.writeHeader(Tag.SequenceDelimitationItem, null, 0); } if (offsetFirstRootRecord() != filesetInfo.getOffsetFirstRootRecord()) { offsetFirstRootRecord(filesetInfo.getOffsetFirstRootRecord()); } if (offsetLastRootRecord() != filesetInfo.getOffsetLastRootRecord()) { offsetLastRootRecord(filesetInfo.getOffsetLastRootRecord()); } filesetInfo.setFileSetConsistencyFlag( FileSetInformation.KNOWN_INCONSISTENCIES); recordSeqLen((int) recordSeqLen); raf.seek(firstRecordPos - dirInfoHeader.length); raf.write(dirInfoHeader, 0, dirInfoHeader.length); rollbackLen = -1; for (int i = 0, n = dirtyRecords.size(); i < n; i++) { writeDirRecordHeader(dirtyRecords.get(i)); } dirtyRecords.clear(); raf.seek(firstRecordPos - 14); raf.writeShort(FileSetInformation.NO_KNOWN_INCONSISTENCIES); filesetInfo.setFileSetConsistencyFlag( FileSetInformation.NO_KNOWN_INCONSISTENCIES); }
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);
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); } } }
writeHeader(a.tag(), vr, len); a.bigEndian(ts.bigEndian()); if (a.hasItems()) { 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) writeHeader(Tag.SequenceDelimitationItem, null, 0);