public DicomDirReader(RandomAccessFile raf) throws IOException { this.raf = raf; in = new DicomInputStream(raf); in.setHandler(new StopTagInputHandler(Tag.DirectoryRecordSequence)); filesetInfo = new FileSetInformation(); in.readDicomObject(filesetInfo.getDicomObject(), -1); in.setHandler(in); }
public boolean readValue(DicomInputStream in) throws IOException { boolean skip = isSkip(in); if(!skip){ if (subHandler != null){ return subHandler.readValue(in); }else{ return in.readValue(in); } } in.getDicomObject().add(new SkippedDicomElement(in.tag(), in.vr(), false, in.valueLength(), in.getStreamPosition())); in.skip(in.valueLength()); return true; }
private long endPos() throws IOException { if (recordSeqLen == -1) { long endPos = raf.length() - 12; raf.seek(endPos); if (in.readHeader() == Tag.SequenceDelimitationItem) { recordSeqLen = (int) (endPos - firstRecordPos); } else { endPos = filesetInfo.getOffsetLastRootRecord(); raf.seek(endPos); in.setStreamPosition(endPos); DicomObject dcmobj = new BasicDicomObject(); while (in.readHeader() == Tag.Item) { in.readDicomObject(dcmobj, in.valueLength()); dcmobj.clear(); endPos = in.getStreamPosition(); } if (in.tag() != Tag.SequenceDelimitationItem) { throw new IOException("Unexpected Tag " + TagUtils.toString(in.tag()) + " at offset " + endPos); } recordSeqLen = (int) (endPos - firstRecordPos); } } return firstRecordPos + recordSeqLen; }
private boolean hasZLIBHeader() throws IOException { if (!markSupported()) return false; byte[] buf = header; mark(2); read(buf, 0, 2); reset(); return ((((buf[0] & 0xff) << 8) | (buf[1] & 0xff)) == ZLIB_HEADER); }
return; dis = new DicomInputStream(iis); DicomInputHandler ih = new StopTagInputHandler(Tag.PixelData); if( isSkipLargePrivate() ) { ih = new SizeSkipInputHandler(ih); dis.setHandler(ih); ds = dis.readDicomObject(); streamMetaData = new DicomStreamMetaData(); fixHeaderData(ds); streamMetaData.setDicomObject(ds); bigEndian = dis.getTransferSyntax().bigEndian(); tsuid = ds.getString(Tag.TransferSyntaxUID); width = ds.getInt(Tag.Columns); if (dis.tag() == Tag.PixelData) { streamMetaData.setPixelData(true); if (frames == 0) frames = 1; swapByteOrder = bigEndian && dis.vr() == VR.OW && dataType == DataBuffer.TYPE_BYTE; if (swapByteOrder && banded) { pixelDataPos = dis.getStreamPosition(); pixelDataLen = dis.valueLength(); compressed = pixelDataLen == -1; verifyTransferSyntax();
DicomInputStream in = null; try { in = new DicomInputStream(inStream); in.setHandler(new StopTagInputHandler(Tag.StudyDate)); in.readDicomObject(dcmObj, PEEK_LEN); info.tsuid = in.getTransferSyntax().uid(); info.fmiEndPos = in.getEndOfFileMetaInfoPosition(); } catch (IOException e) { e.printStackTrace();
if (info.f.getAbsolutePath().endsWith(".gz")) dis = new DicomInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(info.f), 256))); dis= new DicomInputStream(info.f); dis.setHandler(new StopTagInputHandler(Tag.PixelData)); attrs = dis.readDicomObject(); } finally { dis.close(); if (info.f.getAbsolutePath().endsWith(".gz")) dis = new DicomInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(info.f), 256))); dis = new DicomInputStream(info.f); TranscoderInputHandler h = new TranscoderInputHandler(dos, transcoderBufferSize); dis.setHandler(h); dis.readDicomObject(); } finally { dis.close();
private void transcodeAttribute(DicomInputStream in) throws SAXException, IOException { final int tag = in.tag(); final VR vr = in.vr(); final int vallen = in.valueLength(); final DicomObject attrs = in.getDicomObject(); final String tagHex = StringUtils.intToHex(tag); if (file != null) startAttributeElement(tag, vr, vallen, fpath, attrs); if (vallen == -1 || vr == VR.SQ) { in.readValue(in); attrs.remove(tag); } else { byte[] val = in.readBytes(vallen); final boolean bigEndian = in.getTransferSyntax().bigEndian(); if (fpath != null) { writeToFile(val); in.setEndOfFileMetaInfoPosition( in.getStreamPosition() + vr.toInt(val, bigEndian));
public void readPostPixeldata() throws IOException{ readMetaData(); long currentPosition = dis.getStreamPosition(); dis.reset(); dis.reset(); DicomInputStream postDis = new DicomInputStream(iis, TransferSyntax.valueOf(tsuid)); if( isSkipLargePrivate() ) { DicomInputHandler dih = new SizeSkipInputHandler(null); postDis.setHandler(dih); final DicomObject postPixelDs = postDis.readDicomObject(); if (postPixelDs != null && !postPixelDs.isEmpty()) {
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); } } }
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); DicomInputStream dis = new DicomInputStream(s, TransferSyntax.ExplicitVRLittleEndian); attrs = new BasicDicomObject(); dis.readDicomObject(attrs, -1); } }
private void transcodeItem(DicomInputStream in) throws SAXException, IOException { final DicomElement sq = in.sq(); final int itemLen = in.valueLength(); final VR sqvr = sq.vr(); final int index = sq.countItems(); if (file != null) file = new File(file, Integer.toString(index+1)); final String fpath = fpath(sq.tag(), sqvr, itemLen); startItemElement(in.tagPosition(), itemLen, fpath); in.readValue(in); if (sq.hasFragments() && index < sq.countItems()) { byte[] data = sq.getFragment(index); if (fpath != null) { writeToFile(data); } else { final boolean bigEndian = in.getTransferSyntax().bigEndian(); sqvr.formatXMLValue(data, bigEndian, null, cbuf, ch); } sq.setFragment(index, EMPTY_BYTES); // allow gc to release byte[] } endItemElement(); if (file != null) file = file.getParentFile(); }
byte[] b = sq.getFragment(i); InputStream is = new ByteArrayInputStream(b); DicomInputStream dis1 = new DicomInputStream(is, TransferSyntax.ImplicitVRLittleEndian); DicomObject item = new BasicDicomObject(); dis1.readDicomObject(item, b.length); tmp.addDicomObject(item); item.setParent(attrs); item.setItemOffset(tagpos); readDicomObject(item, vallen); sq.addDicomObject(item); } else { sq.addFragment(readBytes(vallen));
public void readItem(DicomObject dest) throws IOException { dest.setItemOffset(pos); if (readHeader() != Tag.Item) throw new DicomCodingException("Expected (FFFE,E000) but read " + TagUtils.toString(tag)); readDicomObject(dest, vallen); }
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; } }
if (!items.isEmpty()) iis.seek(last().nextItemPos()); dis.readHeader(); if (log.isDebugEnabled()) log.debug("Read " + TagUtils.toString(dis.tag()) + " #" + dis.valueLength()); if (dis.tag() == Tag.Item) { Item item = new Item( items.isEmpty() ? 0 : last().nextOffset(), iis.getStreamPosition(), dis.valueLength()); if (items.isEmpty() || rle) { addFirstItemOfFrame(item); log.warn("i/o error reading next item:", e); if (dis.tag() != Tag.SequenceDelimitationItem || dis.valueLength() != 0) { log.warn("expected (FFFE,E0DD) #0 but read " + TagUtils.toString(dis.tag()) + " #" + dis.valueLength());
int tag0 = 0; while (!quit && tag0 != endTag && pos < endPos) { mark(12); try { tag0 = readHeader(); } catch (EOFException e) { if (len != -1) reset(); return; String tsuid = attrs.getString(Tag.TransferSyntaxUID); if (tsuid != null) switchTransferSyntax(TransferSyntax.valueOf(tsuid)); else log.warn("Missing (0002,0010) Transfer Syntax in " +
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); } }
switch (tag) { case Tag.Item: readItemValue(); break; case Tag.ItemDelimitationItem: "Item Length:" + vallen + " at pos: " + tagpos + " - try to skip length"); skip(vallen); "non-zero Item Length:" + vallen + " at pos: " + tagpos + " - try to skip length"); skip(vallen); DicomElement a = vr == VR.SQ ? attrs.putSequence(tag) : attrs .putFragments(tag, vr, ts.bigEndian()); readItems(a, vallen); } else { DicomElement a = attrs.putBytes(tag, vr, readBytes(vallen), ts .bigEndian()); if (tag == 0x00020000) {