Ah, yes, plaincharset. =) 

That's basically a VERY small (4 classes) Charset, which I use to go
from byte[] to Java Strings without having to fuzz with the translation.
I'm going to write about this in my blog tonight, but anyway, here's the
short story:
char[] cs = new char[256];
for(int i=0;i<cs.length;i++) {
  cs[i] = (char)i;
}
String str = String.valueOf(cs);
byte[] bts = str.getBytes(); // or str.getBytes("ASCII"); or
str.getBytes("UTF-8");
for(int i=0;i<256;i++) {
 System.err.println("chr: " + (int)cs[i] + " byte: " + bts[i]);
}


What you will notice is a few places in the middle - different depending
on the encoding you choose when getting bytes - where the bytes are 63,
regardless of the char. This means that we cannot use this to represent
all bytes when we want to get at the underlying bytes. What plaincharset
does is (and it does it pretty fast) translate between char[] and byte[]
arrays such that for i in 0..255 byte[i] == (byte)char[i];

I need it desperately to handle IO work between Ruby-world and
Java-world, and it's probably useful in other places too. Use the
encoding named "PLAIN" and it just works (if plaincharset.jar is on the
classpath).

Regards
 Ola Bini

----- Original Message -----
From: Charles O Nutter <[EMAIL PROTECTED]>
Date: Thursday, June 15, 2006 9:10 pm
Subject: Re: [Jruby-devel] New Zlib.
To: jruby-devel@lists.sourceforge.net

> What's plaincharset?
> 
> On 6/15/06, Ola Bini <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > So here comes the new (partial) Zlib implementation. I've totally
> > rewritten GzipReader and GzipWriter in Java. There are a few 
> steps to
> > get this working, though. First, the new files:
> >
> > plaincharset.jar -> lib/
> > zlib.rb          -> src/builtin    (this is very important)
> > RubyZlib.java    -> org/jruby
> > ZlibLibrary.java -> org/jruby/libraries
> >
> > src/lib/ruby/1.8/zlib.rb should be removed
> >
> > My new RubyStringIO and company is needed for this to work.
> >
> > and the patch should be applied. but that is a slight problem, since
> > some of my previous updates have been catched by this patch too,
> > especially the StringIO-stuff and the Signal things.
> >
> > ... oh, and yeah, if you're using windows, you have to modify the 
> bat> script to reference everything in lib/*.jar in your classpath, 
> not just
> > jruby.jar
> >
> > ... I hope this is all, good luck and please come back with 
> comments!>
> > /O
> >
> >
> >
> >
> > _______________________________________________
> > Jruby-devel mailing list
> > Jruby-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/jruby-devel
> >
> >
> >
> >
> 
> 
> -- 
> Charles Oliver Nutter @ headius.blogspot.com
> JRuby Developer @ jruby.sourceforge.net
> Application Architect @ www.ventera.com
> 


_______________________________________________
Jruby-devel mailing list
Jruby-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to