diff options
| author | Ronald Veldema <rveldema@cs.vu.nl> | 2002-03-11 15:46:36 +0000 |
|---|---|---|
| committer | Ronald Veldema <rveldema@cs.vu.nl> | 2002-03-11 15:46:36 +0000 |
| commit | eed4707c499f072d7e36d8499638b859a370fc57 (patch) | |
| tree | 02f838d922421e25f22b280a3dc415208cc910cb /java/nio/charset/CharsetEncoder.java | |
| parent | 0f5a2af52cbab9c19c69b9a7ab4ec3ba200758f3 (diff) | |
| download | classpath-eed4707c499f072d7e36d8499638b859a370fc57.tar.gz | |
java.nio implementation.
Not integrated into makefiles etc though
so nobody should notice its addition.
R.
Diffstat (limited to 'java/nio/charset/CharsetEncoder.java')
| -rw-r--r-- | java/nio/charset/CharsetEncoder.java | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/java/nio/charset/CharsetEncoder.java b/java/nio/charset/CharsetEncoder.java new file mode 100644 index 000000000..5ae2b4c43 --- /dev/null +++ b/java/nio/charset/CharsetEncoder.java @@ -0,0 +1,140 @@ +package java.nio.charset; + +import java.nio.*; + + +public abstract class CharsetEncoder +{ + Charset cs; + float averageBytesPerChar; + float maxBytesPerChar; + byte[] repl; + + protected CharsetEncoder(Charset cs, + float averageBytesPerChar, + float maxBytesPerChar) + { + this(cs, averageBytesPerChar, maxBytesPerChar, null); + } + + protected CharsetEncoder(Charset cs, + float averageBytesPerChar, + float maxBytesPerChar, + byte[] replacement) + { + this.cs = cs; + this.maxBytesPerChar = maxBytesPerChar; + this.averageBytesPerChar = averageBytesPerChar; + this.repl = replacement; + } + + float averageBytesPerChar() + { + return averageBytesPerChar; + } + + boolean canEncode(char c) + { + return true; + } + + boolean canEncode(CharSequence cs) + { + return true; + } + + Charset charset() + { + return cs; + } + + ByteBuffer encode(CharBuffer in) + { + ByteBuffer x = ByteBuffer.allocate(in.remaining()); + encode(in, x, false); + + return x; + } + + CoderResult encode(CharBuffer in, ByteBuffer out, boolean endOfInput) + { + return encodeLoop(in, out); + } + + + protected abstract CoderResult encodeLoop(CharBuffer in, ByteBuffer out); + + + + CoderResult flush(ByteBuffer out) + { + return implFlush(out); + } + + protected CoderResult implFlush(ByteBuffer out) + { + return null; + } + + protected void implOnMalformedInput(CodingErrorAction newAction) + { + } + + protected void implOnUnmappableCharacter(CodingErrorAction newAction) + { + } + + protected void implReplaceWith(byte[] newReplacement) + { + } + + protected void implReset() + { + } + + boolean isLegalReplacement(byte[] repl) + { + return true; + } + + CodingErrorAction malformedInputAction() + { + return null; + } + + float maxBytesPerChar() + { + return maxBytesPerChar; + } + + CharsetEncoder onMalformedInput(CodingErrorAction newAction) + { + return null; + } + + CharsetEncoder onUnmappableCharacter(CodingErrorAction newAction) + { + return null; + } + + byte[] replacement() + { + return repl; + } + + CharsetEncoder replaceWith(byte[] newReplacement) + { + repl = newReplacement; + return null; + } + + CharsetEncoder reset() + { + return null; + } + + CodingErrorAction unmappableCharacterAction() + { + return null; + } +} |
