/** *Sendthebytes(usuallytheinternalconversionbuffer).Expect8koutputifthebufferisfull. * *@parambufcharactersthatwillbewritten *@paramoffoffsetinthecharactersarray *@paramlenlengththatwillbewritten * *@throwsIOExceptionIfanI/Ooccurswhilewritingthecharacters
*/ void realWriteChars(char buf[], int off, int len) throws IOException;
}
// --------------------
// char[] privatechar[] buff;
// transient as serialization is primarily for values via, e.g. JMX privatetransient CharInputChannel in = null; privatetransient CharOutputChannel out = null;
/** *Createsanew,uninitializedCharChunkobject.
*/ public CharChunk() {
}
public CharChunk(int initial) {
allocate(initial, -1);
}
// --------------------
@Override public Object clone() throws CloneNotSupportedException { returnsuper.clone();
}
/** *Adddatatothebuffer. * *@paramsrcChararray *@paramoffOffset *@paramlenLength * *@throwsIOExceptionWritingoverflowdatatotheoutputchannelfailed
*/ publicvoid append(char src[], int off, int len) throws IOException { // will grow, up to limit
makeSpace(len); int limit = getLimitInternal();
// Optimize on a common case. // If the buffer is empty and the source is going to fill up all the // space in buffer, may as well write it directly to the output, // and avoid an extra copy if (len == limit && end == start && out != null) {
out.realWriteChars(src, off, len); return;
}
// if we are below the limit if (len <= limit - end) {
System.arraycopy(src, off, buff, end, len);
end += len; return;
}
// Need more space than we can afford, need to flush buffer.
// The buffer is already at (or bigger than) limit.
// Optimization: // If len-avail < length (i.e. after we fill the buffer with what we // can, the remaining will fit in the buffer) we'll just copy the first // part, flush, then copy the second part - 1 write and still have some // space for more. We'll still have 2 writes, but we write more on the first.
if (len + end < 2 * limit) { /* *Iftherequestlengthexceedsthesizeoftheoutputbuffer,flushtheoutputbufferandthenwritethe *datadirectly.Wecan'tavoid2writes,butwecanwritemoreonthesecond
*/ int avail = limit - end;
System.arraycopy(src, off, buff, end, avail);
end += avail;
flushBuffer();
System.arraycopy(src, off + avail, buff, end, len - avail);
end += len - avail;
} else { // len > buf.length + avail // long write - flush the buffer and write the rest // directly from source
flushBuffer();
/** *ComparesthemessagebytestothespecifiedStringobject. * *@paramstheStringtocompare * *@return<code>true</code>ifthecomparisonsucceeded,<code>false</code>otherwise
*/ publicboolean equals(String s) { char[] c = buff; int len = end - start; if (c == null || len != s.length()) { returnfalse;
} int off = start; for (int i = 0; i < len; i++) { if (c[off++] != s.charAt(i)) { returnfalse;
}
} returntrue;
}
/** *ComparesthemessagebytestothespecifiedStringobject. * *@paramstheStringtocompare * *@return<code>true</code>ifthecomparisonsucceeded,<code>false</code>otherwise
*/ publicboolean equalsIgnoreCase(String s) { char[] c = buff; int len = end - start; if (c == null || len != s.length()) { returnfalse;
} int off = start; for (int i = 0; i < len; i++) { if (Ascii.toLower(c[off++]) != Ascii.toLower(s.charAt(i))) { returnfalse;
}
} returntrue;
}
publicboolean equals(char b2[], int off2, int len2) { char b1[] = buff; if (b1 == null && b2 == null) { returntrue;
}
int len = end - start; if (len != len2 || b1 == null || b2 == null) { returnfalse;
}
int off1 = start;
while (len-- > 0) { if (b1[off1++] != b2[off2++]) { returnfalse;
}
} returntrue;
}
/** *@return<code>true</code>ifthemessagebytesstartswiththespecifiedstring. * *@paramsThestring
*/ publicboolean startsWith(String s) { char[] c = buff; int len = s.length(); if (c == null || len > end - start) { returnfalse;
} int off = start; for (int i = 0; i < len; i++) { if (c[off++] != s.charAt(i)) { returnfalse;
}
} returntrue;
}
/** *Returnstrueifthebufferstartswiththespecifiedstring. * *@paramsthestring *@paramposTheposition * *@return<code>true</code>ifthestartmatches
*/ publicboolean startsWithIgnoreCase(String s, int pos) { char[] c = buff; int len = s.length(); if (c == null || len + pos > end - start) { returnfalse;
} int off = start + pos; for (int i = 0; i < len; i++) { if (Ascii.toLower(c[off++]) != Ascii.toLower(s.charAt(i))) { returnfalse;
}
} returntrue;
}
/** *@return<code>true</code>ifthemessagebytesendwiththespecifiedstring. * *@paramsThestring
*/ publicboolean endsWith(String s) { char[] c = buff; int len = s.length(); if (c == null || len > end - start) { returnfalse;
} int off = end - len; for (int i = 0; i < len; i++) { if (c[off++] != s.charAt(i)) { returnfalse;
}
} returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.