package org.greenstone.gsdl3.gs3build.doctypes; import java.io.*; import java.net.URL; public class DocumentLoader { public static String getAsString(InputStream in) { StringBuffer reply; byte data[] = new byte[1024]; int databytes; reply = new StringBuffer(); try { do { databytes = in.read(data); if (databytes > 0) { reply.append(new String(data, 0, databytes)); } } while (databytes >= 0); } catch (IOException io) { } return reply.toString(); } public static String getAsString(File file) { FileInputStream in; String reply = null; try { in = new FileInputStream(file); if (in == null) { return null; } reply = getAsString(in); in.close(); } catch (IOException io) { return null; } return reply; } public static String getAsString(URL url) { if (url.toString().startsWith("file://")) { File file = new File(url.toString().substring(7)); return getAsString(file); } else if (url.toString().startsWith("file:/")) { File file = new File(url.toString().substring(5)); return getAsString(file); } return null; } }