1 21 package au.id.jericho.lib.html; 22 23 import java.io.*; 24 import java.nio.*; 25 26 31 public final class CharStreamSourceUtil { 32 private static final int DEFAULT_ESTIMATED_MAXIMUM_OUTPUT_LENGTH=2048; 33 34 private CharStreamSourceUtil() {} 35 36 45 public static Reader getReader(final CharStreamSource charStreamSource) { 46 return new StringReader(toString(charStreamSource)); 47 } 48 49 58 public static String toString(final CharStreamSource charStreamSource) { 59 long estimatedMaximumOutputLength=charStreamSource.getEstimatedMaximumOutputLength(); 60 if (estimatedMaximumOutputLength==-1L) estimatedMaximumOutputLength=DEFAULT_ESTIMATED_MAXIMUM_OUTPUT_LENGTH; 61 final StringWriter writer=new StringWriter((int)(estimatedMaximumOutputLength)); 62 try { 63 charStreamSource.writeTo(writer); 64 } catch (IOException ex) {throw new RuntimeException (ex);} return writer.toString(); 66 } 67 } 68 | Popular Tags |