forked from jruby/jruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.codehaus.org/jruby/trunk@2375 961051c9-f516-0410-bf72-c9f7e237a7b7
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
plaincharset/src/java/org/jruby/charset/PlainCharsetProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.jruby.charset.PlainCharsetProvider |