📄 msgunit.java
字号:
* @return never null */ public byte[] getContent() { return this.content; } /** * Convenience method to get the raw content as a string. * @return never null */ public String getContentStr() { return new String(this.content); } /** * The QoS XML string. * @return never null */ public String getQos() { return this.qosData.toXml(); } /** * The parsed key. * @return for PUBLISH/UPDATE never null, otherwise it may be null */ public KeyData getKeyData() { return this.keyData; } /** * The parsed QoS. * Is of type QueryQosData, MsgQosData depending on the MethodName * @return never null */ public QosData getQosData() { return this.qosData; } public String getLogId() { return getKeyOid() + "/" + getQosData().getRcvTimestamp(); } /** * @return null if not known */ public String getContentMime() { return (this.keyData != null) ? this.keyData.getContentMime() : null; } /** * @return null if not known */ public String getContentMimeExtended() { return (this.keyData != null) ? this.keyData.getContentMimeExtended() : null; } /** * @return null if not known */ public String getDomain() { return (this.keyData != null) ? this.keyData.getDomain() : null; } /** * Deep clone this message unit. * <p /> * The content byte[] is new allocated (a copy), the key an qos objects * are shallow cloned (the String, int etc are clones there) */ public MsgUnit getClone() { byte[] newContent = new byte[content.length]; System.arraycopy(this.content, 0, newContent, 0, this.content.length); return new MsgUnit((this.keyData==null)?null:(KeyData)this.keyData.clone(), content, (QosData)this.qosData.clone()); } public MsgUnitRaw getMsgUnitRaw() { return new MsgUnitRaw(this, (this.keyData == null) ? null : this.keyData.toXml(), this.content, (this.qosData == null) ? null : this.qosData.toXml()); } /** * Compares bytes if the given content is identical to the * internal content * @return true content is identical */ public boolean sameContent(byte[] newContent) { if (newContent == null) { if (this.content.length < 1) return true; return false; } if (this.content.length != newContent.length) return false; for (int ii=0; ii<newContent.length; ii++) if (this.content[ii] != newContent[ii]) return false; return true; } /** * The number of bytes of qos+key+content */ public long size() { //glob.getLog("core").info("MsgUnit", this.qosData.toXml() + "qosSize=" + this.qosData.size() + " keySize=" + this.keyData.size() + " contentSize=" + this.content.length + this.qosData.toXml()); return this.qosData.size() + ((this.keyData==null)?0:this.keyData.size()) + this.content.length; } /** * Dump state of this object into a XML ASCII string. * <br> * @return The data of this MsgUnit as a XML ASCII string */ public String toXml() { return toXml((String)null, -1, false); } /** * Dump state of this object into a XML ASCII string. * <br> * @param extraOffset indenting of tags for nice output * @return The data of this MsgUnit as a XML ASCII string */ public String toXml(String extraOffset) { return toXml(extraOffset, -1, false); } /** * Overwrite QosData.toXml() * @param extraOffset * @param forceReadable * @return */ public String toXml(String extraOffset, boolean forceReadable) { return toXml(extraOffset, -1, forceReadable); } /** * Dump state of this object into a XML ASCII string. * <br> * Needs to be portable for XmlScripting * @param extraOffset indenting of tags for nice output * @param maxContentLen For huge content length you can choose to display * only the given size of the content (from the beginning), the rest is not dumped.<br /> * -1 dumps the complete content<br /> * 0 dumps no content * @return The data of this MsgUnit as a XML ASCII string */ public String toXml(String extraOffset, int maxContentLen, boolean forceReadable) { Properties props = new Properties(); props.put(Constants.TOXML_MAXCONTENTLEN, ""+maxContentLen); props.put(Constants.TOXML_FORCEREADABLE, ""+forceReadable); return toXml(extraOffset, props); } public String toXml(String extraOffset, Properties props) { MsgUnitRaw msgUnitRaw = new MsgUnitRaw( (this.keyData != null) ? this.keyData.toXml(extraOffset) : "", this.content, this.qosData.toXml(extraOffset, props)); ByteArrayOutputStream out = new ByteArrayOutputStream(); try { msgUnitRaw.toXml(extraOffset, out, props); return out.toString(Constants.UTF8_ENCODING); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException("Can't dump message to xml: " + e.toString()); } } public final void toXml(java.io.OutputStream out, java.util.Properties props) throws java.io.IOException { toXml(null, out, props); } /** * Dump status as XML to outstream. * @param extraOffset Indenting, can be null * @param out Destination * @param props Configuration settings * @throws java.io.IOException */ private final void toXml(String extraOffset, java.io.OutputStream out, java.util.Properties props) throws java.io.IOException { String offset = "\n"; if (extraOffset == null) { extraOffset = (props!=null && props.containsKey(Constants.TOXML_EXTRAOFFSET)) ? ((String)props.get(Constants.TOXML_EXTRAOFFSET)) : ""; // "extraOffset" } offset += extraOffset; byte[] offsetB = offset.getBytes(); byte[] offsetB2 = offsetB; final boolean forceReadable = (props!=null) && props.containsKey(Constants.TOXML_FORCEREADABLE) ? (Boolean.valueOf(props.getProperty(Constants.TOXML_FORCEREADABLE)).booleanValue()) : false; // "forceReadable" final String enclosingTag = (props!=null && props.containsKey(Constants.TOXML_ENCLOSINGTAG)) ? ((String)props.get(Constants.TOXML_ENCLOSINGTAG)) : null; // "enclosingTag" if (enclosingTag != null) { offsetB2 = (offset+" ").getBytes(); out.write(offsetB); out.write(("<" + enclosingTag + ">").getBytes()); } String qosXml = (qosData==null) ? "" : qosData.toXml(extraOffset, props); if (qosXml.length() > 0) { out.write(offsetB2); out.write(qosXml.getBytes()); } String keyXml = (keyData==null) ? "" : keyData.toXml(extraOffset); if (keyXml.length() > 0) { out.write(offsetB2); out.write(keyXml.getBytes()); } if (this.content == null || this.content.length == 0) { return; } MsgUnitRaw.dumpContent(extraOffset, out, this.content, forceReadable); if (enclosingTag != null) { out.write(offsetB); out.write(("</" + enclosingTag + ">").getBytes()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -