/** * Loads the content of the page from a file (see {@link TextAction#locateTextFile()}). * Assigns the {@link TextAction#content} field. * @throws IOException if there's a problem loading the content. */ protected void loadContent() throws IOException { textFile = locateTextFile(); try { content = FileUtils.readFileToString(textFile, CONTENT_ENCODING); content = processContentBeforeView(content); } catch (FileNotFoundException e) { content = EMPTY_STRING; logger.debug("Content file not found. Content set to empty.", e); } }
/** * Saves the content of the page to a file (see {@link TextAction#locateTextFile()}). * @throws IOException if there's a problem saving the content. */ protected void saveContent() throws IOException { if (content == null) { content = EMPTY_STRING; } content = processContentBeforeSave(content); byte[] contentByteArray = content.getBytes(CONTENT_ENCODING); textFile = locateTextFile(); // copy the data FileOutputStream fileOutputStream = new FileOutputStream(textFile); try { long size = IOUtils.copyLarge( new ByteArrayInputStream(contentByteArray), fileOutputStream); } catch (IOException e) { logger.error("Could not save content", e); throw e; } finally { fileOutputStream.close(); } logger.info("Content saved to: {}", textFile.getAbsolutePath()); }