public String getString(SpecificCharacterSet cs, boolean cache) { if (cache) { Object tmp = cachedValue; if (tmp instanceof String) return (String) tmp; } String val = vr.toString(value, bigEndian, cs); if (cache) cachedValue = val; return val; }
private static String[] bytes2strs(byte[] val, SpecificCharacterSet cs) { return StringUtils.split(VR.bytes2str(val, cs), '\\'); }
private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeInt(tag); s.writeShort(vr.code()); s.writeBoolean(bigEndian); s.writeInt(value.length); if (value.length != 0) { s.write(value); } }
public DicomElement putString(int tag, VR vr, String val) { final boolean be = bigEndian(); if (vr == null) vr = vrOf(tag); return addInternal(new SimpleDicomElement(tag, vr, be, vr.toBytes(val, be, getSpecificCharacterSet()), cachePut && vr.isSingleValue(val) ? val : null)); }
public DicomElement putStrings(int tag, VR vr, String[] val) { final boolean be = bigEndian(); if (vr == null) vr = vrOf(tag); return addInternal(new SimpleDicomElement(tag, vr, be, vr.toBytes(val, be, getSpecificCharacterSet()), cachePut && vr.containsSingleValues(val) ? val : null)); }
if (TagUtils.hasVR(tag) && ts.explicitVR()) { try { vr = VR.valueOf(((header[4] & 0xff) << 8) | (header[5] & 0xff)); } catch (IllegalArgumentException e) { vr = attrs.vrOf(tag); + " - assume " + vr); if (vr.explicitVRHeaderLength() == 8) { vallen = ts.bigEndian() ? ByteUtils.bytesBE2ushort(header, 6) : ByteUtils.bytesLE2ushort(header, 6);
writeToFile(val); } else { vr.formatXMLValue(val, bigEndian, attrs.getSpecificCharacterSet(), cbuf, ch); in.getStreamPosition() + vr.toInt(val, bigEndian));
ByteUtils.ushort2bytesBE(vr.code(), header, 4); if (vr.explicitVRHeaderLength() == 8) { if (ts.bigEndian()) { ByteUtils.ushort2bytesBE(len, header, 6);
private void writeFragment(VR vr, byte[] bytes, boolean bigEndian, String fpath) throws SAXException, IOException { startItemElement(-1, (bytes.length + 1) & ~1, fpath); if (fpath != null) { writeToFile(bytes); } else { vr.formatXMLValue(bytes, bigEndian, null, cbuf, ch); } endItemElement(); }
@Override protected void toChars(byte[] bs, boolean bigEndian, SpecificCharacterSet cs, char[] cbuf, int maxLen, CharOut out) { VR.float2chars(bs, bigEndian, out, cbuf, maxLen); }
public boolean containsSingleValues(String[] vals) { if (vals == null) { return false; } for (String val : vals) { if (!isSingleValue(val)) { return false; } } return true; }
private static byte[] parseShortXMLValue(StringBuffer sb, ByteArrayOutputStream out, boolean last) { if (sb.length() == 0) return null; int begin = 0; int end; while ((end = sb.indexOf("\\", begin)) != -1) { outShortLE(out, Integer.parseInt(sb.substring(begin, end))); begin = end + 1; } String remain = sb.substring(begin); sb.setLength(0); if (!last) { sb.append(remain); return null; } outShortLE(out, Integer.parseInt(remain)); return out.toByteArray(); }
private static byte[] parseFloatXMLValue(StringBuffer sb, ByteArrayOutputStream out, boolean last) { if (sb.length() == 0) return null; int begin = 0; int end; while ((end = sb.indexOf("\\", begin)) != -1) { outIntLE(out, Float.floatToIntBits(Float.parseFloat(sb.substring( begin, end)))); begin = end + 1; } String remain = sb.substring(begin); sb.setLength(0); if (!last) { sb.append(remain); return null; } outIntLE(out, Float.floatToIntBits(Float.parseFloat(remain))); return out.toByteArray(); }
vlen = 8; final int alen = (ts.explicitVR() ? vr.explicitVRHeaderLength() : 8) + vlen;
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(); }
@Override protected void toChars(byte[] val, boolean bigEndian, SpecificCharacterSet cs, char[] cbuf, int maxLen, CharOut out) { VR.float2chars(val, bigEndian, out, cbuf, maxLen); }
public Pattern toPattern(byte[] bs, boolean bigEndian, SpecificCharacterSet cs, boolean ignoreCase) { String s = toString(bs, bigEndian, cs); if (s == null) return null; StringBuffer sb = new StringBuffer(s.length() + 10); StringTokenizer stk = new StringTokenizer(s, "*?", true); while (stk.hasMoreTokens()) { String tk = stk.nextToken(); char c = tk.charAt(0); if (c == '*') { sb.append(".*"); } else if (c == '?') { sb.append("."); } else { sb.append("\\Q").append(tk).append("\\E"); } } return Pattern.compile(sb.toString(), ignoreCase ? (Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE) : 0); }
private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); s.writeInt(tag); s.writeShort(vr.code()); s.writeBoolean(bigEndian); int size = items.size(); s.writeInt(size); for (int i = 0; i < size; ++i) { Object item = items.get(i); if (item instanceof DicomObject) { s.writeObject(new ElementSerializer((DicomObject) item)); } else { s.writeObject(item); } } }
private void writeElement(DicomObject attrs, DicomElement a) throws SAXException, IOException { VR vr = a.vr(); final int tag = a.tag(); if (file != null) file = new File(file, StringUtils.intToHex(tag)); String fpath = fpath(tag, vr, a.length()); startAttributeElement(tag, vr, a.length(), fpath, attrs); if (a.hasItems()) { for (int i = 0, n = a.countItems(); i < n; ++i) { writeItem(a, i); } } else { if (fpath != null) { writeToFile(a.getBytes()); } else { vr.formatXMLValue(a.getBytes(), a.bigEndian(), attrs.getSpecificCharacterSet(), cbuf, ch); } } endAttributeElement(); if (file != null) file = file.getParentFile(); }
private static String bytes2str1(byte[] val, SpecificCharacterSet cs) { return StringUtils.first(VR.bytes2str(val, cs), '\\'); }