Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added plaincharset as sub-project.

git-svn-id: http://svn.codehaus.org/jruby/trunk@2375 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 2b5808784bfbab5fc72bd1a2b79dbf3fbe2174ea 1 parent 04aa741
@olabini olabini authored
View
49 plaincharset/build.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project basedir="." default="jar" name="PlainCharset">
+ <description></description>
+ <property file="build.properties"/>
+ <property file="default.build.properties"/>
+
+ <path id="build.classpath">
+ <fileset dir="${lib.dir}" includes="*.jar" excludes="plaincharset.jar"/>
+ </path>
+
+ <patternset id="java.src.pattern">
+ <include name="**/*.java"/>
+ </patternset>
+
+ <target name="prepare" description="Creates the directories needed for building">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${classes.dir}"/>
+ <mkdir dir="${charset.classes.dir}"/>
+ </target>
+
+ <target name="compile" depends="prepare" description="Compile the source files for the project.">
+ <javac destdir="${charset.classes.dir}" debug="true" source="${javac.version}">
+ <classpath refid="build.classpath"/>
+ <src path="${src.dir}"/>
+ <patternset refid="java.src.pattern"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile" description="Create the plaincharset.jar file">
+ <jar destfile="${lib.dir}/plaincharset.jar">
+ <metainf dir="src">
+ <include name="services/*"/>
+ </metainf>
+ <fileset dir="${charset.classes.dir}">
+ <include name="**/*.class"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ <manifest>
+ <attribute name="Built-By" value="${user.name}"/>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="clean" depends="prepare" description="clean almost everything">
+ <delete dir="${build.dir}"/>
+ <delete file="${lib.dir}/plaincharset.jar" quiet="true"/>
+ </target>
+</project>
View
9 plaincharset/default.build.properties
@@ -0,0 +1,9 @@
+# Defaults. To override, create a file called build.properties in
+# the same directory and put your changes in that.
+src.dir=src/java
+lib.dir=lib
+build.dir=build
+classes.dir=${build.dir}/classes
+charset.classes.dir=${classes.dir}/charset
+docs.dir=docs
+javac.version=1.4
View
58 plaincharset/src/java/org/jruby/charset/PlainCharset.java
@@ -0,0 +1,58 @@
+package org.jruby.charset;
+
+import java.util.Iterator;
+
+import java.nio.CharBuffer;
+import java.nio.ByteBuffer;
+
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+
+public class PlainCharset extends Charset {
+ public PlainCharset() {
+ super("PLAIN", new String[0]);
+ }
+ public boolean contains(final Charset chs) {
+ return chs instanceof PlainCharset;
+ }
+
+ public CharsetDecoder newDecoder() {
+ return new PlainCharsetDecoder(this);
+ }
+
+ public CharsetEncoder newEncoder() {
+ return new PlainCharsetEncoder(this);
+ }
+
+ private static class PlainCharsetDecoder extends CharsetDecoder {
+ PlainCharsetDecoder(final PlainCharset charset) {
+ super(charset,1F,1F);
+ }
+ public CoderResult decodeLoop(final ByteBuffer in, final CharBuffer out) {
+ while(in.remaining() > 0 && out.remaining() > 0) {
+ out.put((char)in.get());
+ }
+ if(in.remaining() > 0) {
+ return CoderResult.OVERFLOW;
+ }
+ return CoderResult.UNDERFLOW;
+ }
+ }
+
+ private static class PlainCharsetEncoder extends CharsetEncoder {
+ PlainCharsetEncoder(final PlainCharset charset) {
+ super(charset,1F,1F);
+ }
+ public CoderResult encodeLoop(final CharBuffer in, final ByteBuffer out) {
+ while(in.remaining() > 0 && out.remaining() > 0) {
+ out.put((byte)in.get());
+ }
+ if(in.remaining() > 0) {
+ return CoderResult.OVERFLOW;
+ }
+ return CoderResult.UNDERFLOW;
+ }
+ }
+}
View
32 plaincharset/src/java/org/jruby/charset/PlainCharsetProvider.java
@@ -0,0 +1,32 @@
+package org.jruby.charset;
+
+import java.util.Iterator;
+
+import java.nio.charset.Charset;
+import java.nio.charset.spi.CharsetProvider;
+
+public class PlainCharsetProvider extends CharsetProvider {
+ public Charset charsetForName(final String name) {
+ if(name.compareToIgnoreCase("plain") == 0) {
+ return new PlainCharset();
+ }
+ return null;
+ }
+ private static class CharsetIterator implements Iterator {
+ private boolean next = true;
+ public boolean hasNext() {
+ return next;
+ }
+
+ public Object next() {
+ next = false;
+ return new PlainCharset();
+ }
+ public void remove() {
+ }
+ }
+
+ public Iterator charsets() {
+ return new CharsetIterator();
+ }
+}
View
1  plaincharset/src/services/java.nio.charset.spi.CharsetProvider
@@ -0,0 +1 @@
+org.jruby.charset.PlainCharsetProvider
Please sign in to comment.
Something went wrong with that request. Please try again.