private ByteList convertLFToCRLF(ByteList bs) { if (bs == null || binmode) return bs; byte[] crBytes = crBytes(bs.getEncoding()); byte[] lfBytes = lfBytes(bs.getEncoding()); int p = bs.getBegin(); int end = p + bs.getRealSize(); byte[]bytes = bs.getUnsafeBytes(); Encoding enc = bs.getEncoding(); ByteList result = new ByteList(); int lastWrittenIndex = p; while (p < end) { int c = enc.mbcToCode(bytes, p, end); int cLength = enc.codeToMbcLength(c); if (c == LF) { result.append(bytes, lastWrittenIndex, p - lastWrittenIndex); result.append(crBytes); result.append(lfBytes); lastWrittenIndex = p + cLength; } p += cLength; } if (lastWrittenIndex < end) { result.append(bytes, lastWrittenIndex, end - lastWrittenIndex); } return result; }
private ByteList convertLFToCRLF(ByteList bs) { if (bs == null || binmode) return bs; byte[] crBytes = crBytes(bs.getEncoding()); byte[] lfBytes = lfBytes(bs.getEncoding()); int p = bs.getBegin(); int end = p + bs.getRealSize(); byte[]bytes = bs.getUnsafeBytes(); Encoding enc = bs.getEncoding(); ByteList result = new ByteList(); int lastWrittenIndex = p; while (p < end) { int c = enc.mbcToCode(bytes, p, end); int cLength = enc.codeToMbcLength(c); if (c == LF) { result.append(bytes, lastWrittenIndex, p - lastWrittenIndex); result.append(crBytes); result.append(lfBytes); lastWrittenIndex = p + cLength; } p += cLength; } if (lastWrittenIndex < end) { result.append(bytes, lastWrittenIndex, end - lastWrittenIndex); } return result; }
private ByteList convertLFToCRLF(ByteList bs) { if (bs == null || binmode) return bs; byte[] crBytes = crBytes(bs.getEncoding()); byte[] lfBytes = lfBytes(bs.getEncoding()); int p = bs.getBegin(); int end = p + bs.getRealSize(); byte[]bytes = bs.getUnsafeBytes(); Encoding enc = bs.getEncoding(); ByteList result = new ByteList(); int lastWrittenIndex = p; while (p < end) { int c = enc.mbcToCode(bytes, p, end); int cLength = enc.codeToMbcLength(c); if (c == LF) { result.append(bytes, lastWrittenIndex, p - lastWrittenIndex); result.append(crBytes); result.append(lfBytes); lastWrittenIndex = p + cLength; } p += cLength; } if (lastWrittenIndex < end) { result.append(bytes, lastWrittenIndex, end - lastWrittenIndex); } return result; }
private ByteList convertLFToCRLF(ByteList bs) { if (bs == null || binmode) return bs; byte[] crBytes = crBytes(bs.getEncoding()); byte[] lfBytes = lfBytes(bs.getEncoding()); int p = bs.getBegin(); int end = p + bs.getRealSize(); byte[]bytes = bs.getUnsafeBytes(); Encoding enc = bs.getEncoding(); ByteList result = new ByteList(); int lastWrittenIndex = p; while (p < end) { int c = enc.mbcToCode(bytes, p, end); int cLength = enc.codeToMbcLength(c); if (c == LF) { result.append(bytes, lastWrittenIndex, p - lastWrittenIndex); result.append(crBytes); result.append(lfBytes); lastWrittenIndex = p + cLength; } p += cLength; } if (lastWrittenIndex < end) { result.append(bytes, lastWrittenIndex, end - lastWrittenIndex); } return result; }