PlainTextSerializer is used to read a text file into an 
org.apache.pivot.wtk.text.Document, for use in a TextPane. It is intended to 
parallel a hypothetical HTMLSerializer, which would read basic HTML into a 
Document.

A StringSerializer class doesn't exist because we haven't had any use case for 
one yet. Feel free to submit your code as a patch if you'd like to see it 
included in the platform (this is an open source project, after all).  :-)

G


On Nov 22, 2010, at 6:58 PM, Bill van Melle wrote:

> I noticed that one of the implementations of Serializer<T> is the curiously 
> named PlainTextSerializer, which apparently returns a Document!  I'm trying 
> to imagine what that would be (I couldn't find any (ahem) documentation of 
> Document other than the rather unhelpful javadoc), but meanwhile, what if I 
> really did want to read a web result as plain text?  Am I supposed to use 
> ByteArraySerializer and then convert it to a String?  Not particularly hard, 
> I suppose -- in fact, it's trivial to write my own StringSerializer that uses 
> ByteArraySerializer internally.  I was just wondering why I should be the one 
> to do that :).
> 
> 
> public class StringSerializer implements Serializer<String> {
>     
>     private String encoding = "UTF8";   
> 
>     public StringSerializer() {
>     }
> 
>     public StringSerializer(String encoding) {
>         this.encoding = encoding;
>     }
> 
>     @Override
>     public String getMIMEType(String object) {
>         return "text/plain";
>     }
> 
>     @Override
>     public String readObject(InputStream inputStream) 
>             throws IOException, SerializationException {
>         byte[] bytes = new ByteArraySerializer().readObject(inputStream);
>         return new String(bytes, encoding);
>     }
> 
>     @Override
>     public void writeObject(String object, OutputStream outputStream)
>             throws IOException, SerializationException {
>         byte[] bytes = object.getBytes(encoding);
>         new ByteArraySerializer().writeObject(bytes, outputStream);
>     }
> 
> }

Reply via email to