private ByteList convertCRLFToLF(ByteList input) { if (input == null || binmode) return input; ByteList result = new ByteList(); convertCRLFToLF(input, result); return result; }
public int fwrite(ByteList string) throws IOException, BadDescriptorException { if (isWindows) return stream.fwrite(convertLFToCRLF(string)); return stream.fwrite(convertCRLFToLF(string)); }
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 static Stream maybeWrapWithLineEndingWrapper(Stream stream, ModeFlags modes) { if (modes.isText() || // FIXME: Remove this one textmode is part of transcoding. (Platform.IS_WINDOWS && stream.getDescriptor().getChannel() instanceof SeekableByteChannel && !modes.isBinary())) { return new CRLFStreamWrapper(stream); } return stream; }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
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 static Stream maybeWrapWithLineEndingWrapper(Stream stream, ModeFlags modes) { if (modes.isText() || // FIXME: Remove this one textmode is part of transcoding. (Platform.IS_WINDOWS && stream.getDescriptor().getChannel() instanceof SeekableByteChannel && !modes.isBinary())) { return new CRLFStreamWrapper(stream); } return stream; }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
public ByteList read(int number) throws IOException, BadDescriptorException, EOFException { return convertCRLFToLF(stream.read(number)); }
public int fwrite(ByteList string) throws IOException, BadDescriptorException { if (isWindows) return stream.fwrite(convertLFToCRLF(string)); return stream.fwrite(convertCRLFToLF(string)); }
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 static Stream maybeWrapWithLineEndingWrapper(Stream stream, ModeFlags modes) { if (modes.isText() || // FIXME: Remove this one textmode is part of transcoding. (Platform.IS_WINDOWS && stream.getDescriptor().getChannel() instanceof FileChannel && !modes.isBinary())) { return new CRLFStreamWrapper(stream); } return stream; }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
public ByteList read(int number) throws IOException, BadDescriptorException, EOFException { return convertCRLFToLF(stream.read(number)); }
public int fwrite(ByteList string) throws IOException, BadDescriptorException { if (isWindows) return stream.fwrite(convertLFToCRLF(string)); return stream.fwrite(convertCRLFToLF(string)); }
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 static Stream maybeWrapWithLineEndingWrapper(Stream stream, ModeFlags modes) { if (modes.isText() || // FIXME: Remove this one textmode is part of transcoding. (Platform.IS_WINDOWS && stream.getDescriptor().getChannel() instanceof FileChannel && !modes.isBinary())) { return new CRLFStreamWrapper(stream); } return stream; }
public ByteList fread(int number) throws IOException, BadDescriptorException, EOFException { if (number == 0) { if (stream.feof()) { return null; } else { return new ByteList(0); } } boolean eof = false; ByteList bl = new ByteList(number > ChannelStream.BUFSIZE ? ChannelStream.BUFSIZE : number); for (int i = 0; i < number; i++) { int c = fgetc(); if (c == -1) { eof = true; break; } bl.append(c); } if (eof && bl.length() == 0) { return null; } return bl; }
public ByteList fgets(ByteList separatorString) throws IOException, BadDescriptorException, EOFException { return convertCRLFToLF(stream.fgets(separatorString)); }
public int fwrite(ByteList string) throws IOException, BadDescriptorException { if (isWindows) return stream.fwrite(convertLFToCRLF(string)); return stream.fwrite(convertCRLFToLF(string)); }