@Override public String getContent() throws FileNotFound, CannotReadFile { try { Reader input; if (charsetName != null) { input = new InputStreamReader(new FileInputStream(getInputFile()), charsetName); } else { input = new FileReader(getInputFile()); } try { String content = IOUtils.toString(input).replace("\r\n", "\n"); setLastModified(getInputFile().lastModified()); return content; } finally { input.close(); } } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
@Override public String getContent() throws FileNotFound, CannotReadFile { // Adapted from Less's URLSource Reader input = null; try { input = new InputStreamReader(resource.openStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } }
@Override public String getContent() throws FileNotFound, CannotReadFile { // Adapted from Less's URLSource Reader input = null; try { input = new InputStreamReader(resource.openStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { Reader input = null; try { input = new InputStreamReader(resource.openStream()); return IOUtils.toByteArray(input); } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } } }
@Override public LessSource relativeSource(String filename) throws FileNotFound { // First look at files located in the same directory than the current one, if there is a current one if (file != null) { File currentDir = file.getParentFile(); File newFile = new File(currentDir, filename); if (newFile.exists()) { return new MultiPathFileSource(newFile, charsetName, this.includePaths); } } // then look inside the include paths for (int i = 0; i < includePaths.length; ++i) { File directory = includePaths[i]; File newFile = new File(directory, filename); if (newFile.exists()) { return new MultiPathFileSource(newFile, charsetName, this.includePaths); } } // The file has not been found throw new FileNotFound(); }
@Override public LessSource relativeSource(String filename) throws CannotReadFile, FileNotFound { if (filename.startsWith("/webjars/")) { URL webjarResource = ClassPaths.getResource("META-INF/resources" + filename); if (webjarResource == null) { throw new FileNotFound(); } return new LessSource.URLSource(webjarResource); } Path relativePath = Paths.get(filename); if (!resources.exists(relativePath)) { throw new FileNotFound(); } try { return new PathSource(resources, resources.sourceFile(relativePath)); } catch (IOException e) { throw new CannotReadFile(); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { Reader input = null; try { input = new InputStreamReader(resource.openStream()); return IOUtils.toByteArray(input); } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } finally { InternalUtils.close(input); } } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { try { URLConnection connection = getInputURL().openConnection(); Reader input = new InputStreamReader(connection.getInputStream()); setLastModified(connection.getLastModified()); byte[] content = IOUtils.toByteArray(input); input.close(); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
@Override public String getContent() throws FileNotFound, CannotReadFile { try { URLConnection connection = getInputURL().openConnection(); Reader input = charsetName != null ? new InputStreamReader(connection.getInputStream(), charsetName) : new InputStreamReader(connection.getInputStream()); String content = IOUtils.toString(input).replace("\r\n", "\n"); setLastModified(connection.getLastModified()); input.close(); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }
@Override public LessSource relativeSource(String filename) throws FileNotFound, CannotReadFile, StringSourceException { Resource relative = resource.forFile(filename); if (!relative.exists()) { throw new FileNotFound(); } dependencies.addDependency(relative); return new ResourceLessSource(relative, dependencies); }
@Override public LessSource relativeSource(String filename) throws FileNotFound { // look inside the include paths for (int i = 0; i < includePaths.length; ++i) { File directory = includePaths[i]; File newFile = new File(directory, filename); if (newFile.exists()) { return new MultiPathFileSource(newFile, charsetName, this.includePaths); } } // The file has not been found throw new FileNotFound(); }
public URLSource(URLSource parent, String filename, String charsetName) throws FileNotFound, CannotReadFile { super(parent); try { this.inputURL = new URL(URIUtils.toParentURL(parent.inputURL), filename); } catch (MalformedURLException e) { throw new FileNotFound(); } this.charsetName = charsetName; parent.addImportedSource(this); }
@Override public LessSource relativeSource(String filename) throws FileNotFound, CannotReadFile, StringSourceException { Resource relative = resource.forFile(filename); if (!relative.exists()) { throw new FileNotFound(); } dependencies.addDependency(relative); return new ResourceLessSource(relative, dependencies); }
@Override public LessSource relativeSource(String filename) throws FileNotFound { String template = folder + "/" + filename; Resource resource = skin.getResource(template); if (resource != null) { return new TemplateLESSSource(templateManager, skin, template); } // The file has not been found throw new FileNotFound(); } }
@Override public byte[] getBytes() throws FileNotFound, CannotReadFile { try { byte[] content = FileUtils.readFileToByteArray(getInputFile()); setLastModified(getInputFile().lastModified()); return content; } catch (FileNotFoundException ex) { throw new FileNotFound(); } catch (IOException ex) { throw new CannotReadFile(); } }