Java Code Examples for com.google.common.io.Files#append()
The following examples show how to use
com.google.common.io.Files#append() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OperationLogger.java From db with GNU Affero General Public License v3.0 | 6 votes |
public void log(OperationLogLevel level, String opid, String message) throws OperationException { if (!fileMap.containsKey(opid)) { return; } if (level.getLogOrder() < logLevelMap.get(opid).getLogOrder()) { return; } try { Files.append(message, fileMap.get(opid), Charset.forName("UTF8")); } catch (IOException ex) { LoggerFactory.getLogger(OperationLogger.class.getName()).error(null, ex); throw new OperationException(ErrorCode.INTERNAL_OPERATION_ERROR); } }
Example 2
Source File: ServerLoadDataInfileHandler.java From dble with GNU General Public License v2.0 | 6 votes |
private void saveDataToFile(LoadData data, String dnName) { if (data.getFileName() == null) { String dnPath = tempPath + dnName + ".txt"; data.setFileName(dnPath); } File dnFile = new File(data.getFileName()); try { if (!dnFile.exists()) { Files.createParentDirs(dnFile); } Files.append(joinLine(data.getData(), data), dnFile, Charset.forName(loadData.getCharset())); } catch (IOException e) { throw new RuntimeException(e); } finally { data.setData(null); } }
Example 3
Source File: CustomLogger.java From GriefPrevention with MIT License | 6 votes |
void writeEntries() { try { // if nothing to write, stop here if (this.queuedEntries.length() == 0) { return; } // determine filename based on date String filename = this.filenameFormat.format(new Date()) + ".log"; String filepath = this.logFolderPath + File.separator + filename; File logFile = new File(filepath); // dump content Files.append(this.queuedEntries.toString(), logFile, Charset.forName("UTF-8")); // in case of a failure to write the above due to exception, // the unwritten entries will remain the buffer for the next write // to retry this.queuedEntries.setLength(0); } catch (Exception e) { e.printStackTrace(); } }
Example 4
Source File: SimpleFileBasedEventStore.java From bookstore-cqrs-example with Apache License 2.0 | 5 votes |
@Override public synchronized void save(GenericId id, Class<? extends AggregateRoot> type, List<DomainEvent> events) { try { for (DomainEvent event : events) { Files.append(toString(event), eventStoreFile, UTF_8); } } catch (Exception e) { throw new RuntimeException(e); } }
Example 5
Source File: StoredReport.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
private void save(TestCaseResult res) { try { java.nio.file.Files.deleteIfExists(file); Files.append("--------------------------------------------------------\n" + res.toString(), file.toFile(), Charset.defaultCharset()); } catch (IOException e) { throw new IllegalArgumentException(e); } }
Example 6
Source File: TestListenHTTP.java From nifi with Apache License 2.0 | 5 votes |
private File createTextFile(String fileName, String... lines) throws IOException { File file = new File("target/" + fileName); file.deleteOnExit(); for (String string : lines) { Files.append(string, file, Charsets.UTF_8); } return file; }
Example 7
Source File: FileBasedStoreObjectAccessor.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public void append(String val) { try { if (val==null) val = ""; FileUtil.setFilePermissionsTo600(file); Files.append(val, file, Charsets.UTF_8); } catch (IOException e) { throw Exceptions.propagateAnnotated("Problem appending to file "+file, e); } }
Example 8
Source File: S3SinkStreamWriterIntegrationTest.java From Scribengin with GNU Affero General Public License v3.0 | 5 votes |
@Test(expected = AmazonS3Exception.class) public void testBadCredentials() throws Exception { Map<String, String> env = System.getenv(); Map<String, String> fakeEnv = new ConcurrentHashMap<String, String>(); try { File temp = File.createTempFile("fakeCredentials", ".tmp"); String credentials = " #User Name=artfullyContrived \r\n" + "[default] \r\n" + "aws_access_key_id=FAKESTACCESSKEYEVER7338 \r\n" + "aws_secret_access_key=ANOTHEREXTREMELYFAKESECRETACCESSKEY1084 \r\n"; Files.append(credentials, temp, Charsets.UTF_8); fakeEnv.put("AWS_CREDENTIAL_PROFILES_FILE", temp.getCanonicalPath()); fakeEnv.putAll(env); setEnv(fakeEnv); System.out.println("credentitals file " + System.getenv("AWS_CREDENTIAL_PROFILES_FILE")); init("s3.tuplesCountLimited.properties"); int tuples = s3SinkConfig.getChunkSize(); for (int i = 0; i < tuples; i++) { sink.append(new Record(Integer.toString(i), Integer.toString(i).getBytes())); } sink.commit(); } finally { fakeEnv.remove("AWS_CREDENTIAL_PROFILES_FILE"); setEnv(fakeEnv); System.out.println("buckets " + System.getenv("AWS_CREDENTIAL_PROFILES_FILE")); } }
Example 9
Source File: CommandLineSteps.java From datamill with ISC License | 5 votes |
@When("^" + Phrases.SUBJECT + " appends \"(.+)\" in the temporary directory with content:$") public void appendFile(String file, String content) throws IOException { File temporaryDirectory = (File) propertyStore.get(TEMPORARY_DIRECTORY); if (temporaryDirectory == null || !temporaryDirectory.isDirectory()) { fail("A temporary directory was not created!"); } String resolvedFile = placeholderResolver.resolve(file); String resolvedContent = placeholderResolver.resolve(content); File fileWithinDirectory = new File(temporaryDirectory, resolvedFile); Files.append(resolvedContent, fileWithinDirectory, Charset.defaultCharset()); }
Example 10
Source File: FileSystemDropExporter.java From mojito with Apache License 2.0 | 5 votes |
@Override public void addCommentToFile(String fileId, String comment) throws DropExporterException { try { File commentFile = getPathToCommentsFile(fileId).toFile(); Files.createParentDirs(commentFile); Files.append(comment, commentFile, StandardCharsets.UTF_8); } catch (IOException ioe) { throw new DropExporterException("Cannot add comment to file", ioe); } }
Example 11
Source File: ServerLoadDataInfileHandler.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private void saveDataToFile(LoadData data,String dnName) { if (data.getFileName() == null) { String dnPath = tempPath + dnName + ".txt"; data.setFileName(dnPath); } File dnFile = new File(data.getFileName()); try { if (!dnFile.exists()) { Files.createParentDirs(dnFile); } Files.append(joinLine(data.getData(),data), dnFile, Charset.forName(loadData.getCharset())); } catch (IOException e) { throw new RuntimeException(e); }finally { data.setData(null); } }
Example 12
Source File: AppendTextToFile.java From levelup-java-examples with Apache License 2.0 | 5 votes |
@Test public void append_to_file_guava () throws IOException { File file = new File(OUTPUT_FILE_NAME); Files.append("Append text to file w/ guava", file, Charsets.UTF_8); }
Example 13
Source File: JGivenPluginTest.java From JGiven with Apache License 2.0 | 5 votes |
public Given the_plugin_is_applied() throws IOException { Files.append( "plugins { id 'java'; id 'com.tngtech.jgiven.gradle-plugin' }\n", buildFile, Charsets.UTF_8 ); Files.append( "repositories { mavenCentral() }\n", buildFile, Charsets.UTF_8 ); Files.append( "dependencies { testCompile 'com.tngtech.jgiven:jgiven-junit:0.12.1' }\n", buildFile, Charsets.UTF_8 ); Files.append( "dependencies { testCompile 'junit:junit:4.12' }\n", buildFile, Charsets.UTF_8 ); return self(); }
Example 14
Source File: AbstractGeneratorStrategy.java From sloth with Apache License 2.0 | 5 votes |
private void genVersionControllFileAndBackup() { File file = new File(TargetProjectParameters.getTargetProjectStorePath()+"rkill.ver"); try { //TODO Files.append("a",file, Charset.defaultCharset()); } catch (IOException e) { e.printStackTrace(); } }
Example 15
Source File: FileProcessorImpl.java From accelerator-initializer with Mozilla Public License 2.0 | 5 votes |
@Override public void writeContentTo(File target, String content) { try { Files.append(content, target, Charsets.UTF_8); } catch (IOException e) { throw new InitializerException("It was not possible to write content to template", e); } }
Example 16
Source File: DefaultConfigTest.java From apollo with Apache License 2.0 | 4 votes |
@Test public void testGetPropertyWithAllPropertyHierarchy() throws Exception { String someKey = "someKey"; String someSystemPropertyValue = "system-property-value"; String anotherKey = "anotherKey"; String someLocalFileValue = "local-file-value"; String lastKey = "lastKey"; String someResourceValue = "resource-value"; //set up system property System.setProperty(someKey, someSystemPropertyValue); //set up config repo someProperties = new Properties(); someProperties.setProperty(someKey, someLocalFileValue); someProperties.setProperty(anotherKey, someLocalFileValue); when(configRepository.getConfig()).thenReturn(someProperties); someSourceType = ConfigSourceType.LOCAL; when(configRepository.getSourceType()).thenReturn(someSourceType); //set up resource file File resourceFile = new File(someResourceDir, someNamespace + ".properties"); Files.write(someKey + "=" + someResourceValue, resourceFile, Charsets.UTF_8); Files.append(System.getProperty("line.separator"), resourceFile, Charsets.UTF_8); Files.append(anotherKey + "=" + someResourceValue, resourceFile, Charsets.UTF_8); Files.append(System.getProperty("line.separator"), resourceFile, Charsets.UTF_8); Files.append(lastKey + "=" + someResourceValue, resourceFile, Charsets.UTF_8); DefaultConfig defaultConfig = new DefaultConfig(someNamespace, configRepository); String someKeyValue = defaultConfig.getProperty(someKey, null); String anotherKeyValue = defaultConfig.getProperty(anotherKey, null); String lastKeyValue = defaultConfig.getProperty(lastKey, null); //clean up System.clearProperty(someKey); assertEquals(someSystemPropertyValue, someKeyValue); assertEquals(someLocalFileValue, anotherKeyValue); assertEquals(someResourceValue, lastKeyValue); assertEquals(someSourceType, defaultConfig.getSourceType()); }
Example 17
Source File: GivenJsonReports.java From JGiven with Apache License 2.0 | 4 votes |
public SELF a_custom_JS_file_with_content( String content ) throws IOException { File jsFile = temporaryFolderRule.newFile( "custom.js" ); html5ReportConfig.setCustomJs( jsFile ); Files.append( content, jsFile, Charsets.UTF_8 ); return self(); }
Example 18
Source File: TestSqoopPolicyNegative.java From incubator-sentry with Apache License 2.0 | 4 votes |
private void append(String from, File to) throws IOException { Files.append(from + "\n", to, Charsets.UTF_8); }
Example 19
Source File: JGivenPluginTest.java From JGiven with Apache License 2.0 | 4 votes |
public Given the_jgiven_report_is_configured_by( String configuration ) throws IOException { Files.append( "jgivenTestReport { " + configuration + " } ", buildFile, Charsets.UTF_8 ); return self(); }
Example 20
Source File: TestPolicyParsingNegative.java From incubator-sentry with Apache License 2.0 | 4 votes |
private void append(String from, File to) throws IOException { Files.append(from + "\n", to, Charsets.UTF_8); }