/** * Read file input stream to string value. * * @param inputStream * @return * @throws IOException */ public static String readToString(InputStream inputStream) throws IOException { BufferedInputStream reader = new BufferedInputStream(inputStream); StringBuilder builder = new StringBuilder(); byte[] contents = new byte[1024]; int bytesRead = 0; while ((bytesRead = reader.read(contents)) != -1) { builder.append(new String(contents, 0, bytesRead)); } return builder.toString(); }
/** * Returns the path to the view of the relative URI within the Grails views directory * * @param relativeUri The relative URI * @return The path of the URI within the Grails view directory */ protected String getUriWithinGrailsViews(String relativeUri) { StringBuilder buf = new StringBuilder(); String[] tokens; if (relativeUri.startsWith("/")) relativeUri = relativeUri.substring(1); if (relativeUri.indexOf('/') > -1) tokens = relativeUri.split("/"); else tokens = new String[] {relativeUri}; buf.append(GrailsApplicationAttributes.PATH_TO_VIEWS); for (String token : tokens) { buf.append('/').append(token); } if (!relativeUri.endsWith(GroovyPage.EXTENSION)) buf.append(GroovyPage.EXTENSION); return buf.toString(); }