public SVNCharsetOutputStream(OutputStream out, Charset inputCharset, Charset outputCharset) { super(out); myCharsetConvertor = new SVNCharsetConvertor(inputCharset.newDecoder(), outputCharset.newEncoder()); myFlushed = false; }
public SVNCharsetConvertor(CharsetDecoder decoder, CharsetEncoder encoder) { myDecoder = decoder; myEncoder = encoder; reset(); }
result = myDecoder.flush(myCharBuffer); if (result.isError()) { throwException(result); dst = allocate(dst, (int) (myEncoder.maxBytesPerChar() * myCharBuffer.remaining())); result = myEncoder.encode(myCharBuffer, dst, true); if (result.isError()) { throwException(result); throwException(result); reset(); return dst;
public void flush() throws IOException { if (!myFlushed) { try { myOutputBuffer = myCharsetConvertor.convertChunk(EMPTY_ARRAY, 0, 0, myOutputBuffer, true); myOutputBuffer = myCharsetConvertor.flush(myOutputBuffer); myOutputBuffer.flip(); out.write(myOutputBuffer.array(), myOutputBuffer.arrayOffset(), myOutputBuffer.limit()); } catch (SVNException e) { throw new IOExceptionWrapper(e); } finally { myFlushed = true; } } super.flush(); }
public ByteBuffer convertChunk(byte[] b, int offset, int length, ByteBuffer dst, boolean endOfInput) throws SVNException { myInputByteBuffer = allocate(myInputByteBuffer, length); myInputByteBuffer.put(b, offset, length); myInputByteBuffer.flip(); myCharBuffer = allocate(myCharBuffer, (int) (myDecoder.maxCharsPerByte() * myInputByteBuffer.remaining())); CoderResult result = myDecoder.decode(myInputByteBuffer, myCharBuffer, endOfInput); if (result.isError()) { throwException(result); } else if (result.isUnderflow()) { myInputByteBuffer.compact(); } else { myInputByteBuffer.clear(); } myCharBuffer.flip(); dst = allocate(dst, (int) (myEncoder.maxBytesPerChar() * myCharBuffer.remaining())); result = myEncoder.encode(myCharBuffer, dst, false); if (result.isError()) { throwException(result); } else if (result.isUnderflow()) { myCharBuffer.compact(); } else { myCharBuffer.clear(); } return dst; }
public void write(byte[] b, int off, int len) throws IOException { try { myOutputBuffer = myCharsetConvertor.convertChunk(b, off, len, myOutputBuffer, false); myOutputBuffer.flip(); out.write(myOutputBuffer.array(), myOutputBuffer.arrayOffset(), myOutputBuffer.limit()); } catch (SVNException e) { throw new IOExceptionWrapper(e); } }
result = myDecoder.flush(myCharBuffer); if (result.isError()) { throwException(result); dst = allocate(dst, (int) (myEncoder.maxBytesPerChar() * myCharBuffer.remaining())); result = myEncoder.encode(myCharBuffer, dst, true); if (result.isError()) { throwException(result); throwException(result); reset(); return dst;
public void flush() throws IOException { if (!myFlushed) { try { myOutputBuffer = myCharsetConvertor.convertChunk(EMPTY_ARRAY, 0, 0, myOutputBuffer, true); myOutputBuffer = myCharsetConvertor.flush(myOutputBuffer); myOutputBuffer.flip(); out.write(myOutputBuffer.array(), myOutputBuffer.arrayOffset(), myOutputBuffer.limit()); } catch (SVNException e) { throw new IOExceptionWrapper(e); } finally { myFlushed = true; } } super.flush(); }
public ByteBuffer convertChunk(byte[] b, int offset, int length, ByteBuffer dst, boolean endOfInput) throws SVNException { myInputByteBuffer = allocate(myInputByteBuffer, length); myInputByteBuffer.put(b, offset, length); myInputByteBuffer.flip(); myCharBuffer = allocate(myCharBuffer, (int) (myDecoder.maxCharsPerByte() * myInputByteBuffer.remaining())); CoderResult result = myDecoder.decode(myInputByteBuffer, myCharBuffer, endOfInput); if (result.isError()) { throwException(result); } else if (result.isUnderflow()) { myInputByteBuffer.compact(); } else { myInputByteBuffer.clear(); } myCharBuffer.flip(); dst = allocate(dst, (int) (myEncoder.maxBytesPerChar() * myCharBuffer.remaining())); result = myEncoder.encode(myCharBuffer, dst, false); if (result.isError()) { throwException(result); } else if (result.isUnderflow()) { myCharBuffer.compact(); } else { myCharBuffer.clear(); } return dst; }
public void write(byte[] b, int off, int len) throws IOException { try { myOutputBuffer = myCharsetConvertor.convertChunk(b, off, len, myOutputBuffer, false); myOutputBuffer.flip(); out.write(myOutputBuffer.array(), myOutputBuffer.arrayOffset(), myOutputBuffer.limit()); } catch (SVNException e) { throw new IOExceptionWrapper(e); } }
result = myDecoder.flush(myCharBuffer); if (result.isError()) { throwException(result); dst = allocate(dst, (int) (myEncoder.maxBytesPerChar() * myCharBuffer.remaining())); result = myEncoder.encode(myCharBuffer, dst, true); if (result.isError()) { throwException(result); throwException(result); reset(); return dst;
public void flush() throws IOException { if (!myFlushed) { try { myOutputBuffer = myCharsetConvertor.convertChunk(EMPTY_ARRAY, 0, 0, myOutputBuffer, true); myOutputBuffer = myCharsetConvertor.flush(myOutputBuffer); myOutputBuffer.flip(); out.write(myOutputBuffer.array(), myOutputBuffer.arrayOffset(), myOutputBuffer.limit()); } catch (SVNException e) { throw new IOExceptionWrapper(e); } finally { myFlushed = true; } } super.flush(); }
public ByteBuffer convertChunk(byte[] b, int offset, int length, ByteBuffer dst, boolean endOfInput) throws SVNException { myInputByteBuffer = allocate(myInputByteBuffer, length); myInputByteBuffer.put(b, offset, length); myInputByteBuffer.flip(); myCharBuffer = allocate(myCharBuffer, (int) (myDecoder.maxCharsPerByte() * myInputByteBuffer.remaining())); CoderResult result = myDecoder.decode(myInputByteBuffer, myCharBuffer, endOfInput); if (result.isError()) { throwException(result); } else if (result.isUnderflow()) { myInputByteBuffer.compact(); } else { myInputByteBuffer.clear(); } myCharBuffer.flip(); dst = allocate(dst, (int) (myEncoder.maxBytesPerChar() * myCharBuffer.remaining())); result = myEncoder.encode(myCharBuffer, dst, false); if (result.isError()) { throwException(result); } else if (result.isUnderflow()) { myCharBuffer.compact(); } else { myCharBuffer.clear(); } return dst; }
public SVNCharsetInputStream(InputStream in, Charset inputCharset, Charset outputCharset) { super(in); myCharsetConvertor = new SVNCharsetConvertor(inputCharset.newDecoder(), outputCharset.newEncoder()); mySourceBuffer = new byte[DEFAULT_BUFFER_CAPACITY]; myConvertedBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_CAPACITY); myEndOfStream = false; }
public SVNCharsetConvertor(CharsetDecoder decoder, CharsetEncoder encoder) { myDecoder = decoder; myEncoder = encoder; reset(); }
public void write(byte[] b, int off, int len) throws IOException { try { myOutputBuffer = myCharsetConvertor.convertChunk(b, off, len, myOutputBuffer, false); myOutputBuffer.flip(); out.write(myOutputBuffer.array(), myOutputBuffer.arrayOffset(), myOutputBuffer.limit()); } catch (SVNException e) { throw new IOExceptionWrapper(e); } }
public int read(byte b[], int off, int len) throws IOException { int available = myConvertedBuffer.position(); if (myEndOfStream && available == 0){ return -1; } while (available < len) { int readed = fillBuffer(); try { myConvertedBuffer = myCharsetConvertor.convertChunk(mySourceBuffer, 0, readed, myConvertedBuffer, myEndOfStream); if (myEndOfStream) { myConvertedBuffer = myCharsetConvertor.flush(myConvertedBuffer); break; } } catch (SVNException e) { throw new IOExceptionWrapper(e); } finally { available = myConvertedBuffer.position(); } } myConvertedBuffer.flip(); len = Math.min(myConvertedBuffer.remaining(), len); myConvertedBuffer = myConvertedBuffer.get(b, off, len); myConvertedBuffer = myConvertedBuffer.compact(); return len; }
public SVNCharsetInputStream(InputStream in, Charset inputCharset, Charset outputCharset) { super(in); myCharsetConvertor = new SVNCharsetConvertor(inputCharset.newDecoder(), outputCharset.newEncoder()); mySourceBuffer = new byte[DEFAULT_BUFFER_CAPACITY]; myConvertedBuffer = ByteBuffer.allocate(DEFAULT_BUFFER_CAPACITY); myEndOfStream = false; }
public SVNCharsetConvertor(CharsetDecoder decoder, CharsetEncoder encoder) { myDecoder = decoder; myEncoder = encoder; reset(); }
public int read(byte b[], int off, int len) throws IOException { int available = myConvertedBuffer.position(); if (myEndOfStream && available == 0){ return -1; } while (available < len) { int readed = fillBuffer(); try { myConvertedBuffer = myCharsetConvertor.convertChunk(mySourceBuffer, 0, readed, myConvertedBuffer, myEndOfStream); if (myEndOfStream) { myConvertedBuffer = myCharsetConvertor.flush(myConvertedBuffer); break; } } catch (SVNException e) { throw new IOExceptionWrapper(e); } finally { available = myConvertedBuffer.position(); } } myConvertedBuffer.flip(); len = Math.min(myConvertedBuffer.remaining(), len); myConvertedBuffer = myConvertedBuffer.get(b, off, len); myConvertedBuffer = myConvertedBuffer.compact(); return len; }