com.google.common.io.Files Java Examples
The following examples show how to use
com.google.common.io.Files.
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: ReadOnlyDocument.java From javaide with GNU General Public License v3.0 | 6 votes |
/** * Creates a new {@link ReadOnlyDocument} for the given file. * * @param file the file whose text will be stored in the document. UTF-8 charset is used to * decode the contents of the file. * @throws IOException if an error occurs while reading the file. */ @SuppressWarnings("IOResourceOpenedButNotSafelyClosed") ReadOnlyDocument(@NonNull File file) throws IOException { String xml = Files.toString(file, Charsets.UTF_8); if (xml.startsWith("\uFEFF")) { // Strip byte order mark if necessary xml = xml.substring(1); } mFileContents = xml; myFile = file; myLastModified = file.lastModified(); myOffsets = Lists.newArrayListWithExpectedSize(mFileContents.length() / 30); for (int i = 0; i < mFileContents.length(); i++) { char c = mFileContents.charAt(i); if (c == '\n') { myOffsets.add(i + 1); } } }
Example #2
Source File: TestCDep.java From cdep with Apache License 2.0 | 6 votes |
@Test public void testUnknownOverrideBuildSystemNoBuilders() throws Exception { CDepYml config = new CDepYml(); System.out.printf(new Yaml().dump(config)); File yaml = new File(".test-files/testUnknownOverrideBuildSystem/cdep.yml"); deleteDirectory(yaml.getParentFile()); yaml.getParentFile().mkdirs(); Files.write("dependencies:\n" + "- compile: com.github.jomof:sqlite:3.16.2-rev45\n", yaml, StandardCharsets.UTF_8); File modulesFolder = new File(yaml.getParentFile(), "my-modules"); try { main("-wf", yaml.getParent(), "-gmf", modulesFolder.getAbsolutePath(), "--builder", "unknown-build-system"); fail("Expected failure"); } catch (CDepRuntimeException e) { assertThat(e).hasMessage("Builder unknown-build-system is not recognized."); } }
Example #3
Source File: TestReadCustomGeneric.java From kite with Apache License 2.0 | 6 votes |
@BeforeClass public static void setup() throws IOException { fs = LocalFileSystem.getInstance(); testDirectory = new Path(Files.createTempDir().getAbsolutePath()); FileSystemDatasetRepository repo = new FileSystemDatasetRepository(fs.getConf(), testDirectory); Dataset<MyRecord> writerDataset = repo.create("ns", "test", new DatasetDescriptor.Builder() .schema(MyRecord.class) .build(), MyRecord.class); DatasetWriter<MyRecord> writer = writerDataset.newWriter(); for (int i = 0; i < totalRecords; i++) { writer.write(new MyRecord(String.valueOf(i), i)); } writer.close(); readerDataset = repo.load("ns", "test", TestGenericRecord.class); }
Example #4
Source File: HiveShellBaseTest.java From HiveRunner with Apache License 2.0 | 6 votes |
@Test public void executeQueryFromFile() throws IOException { HiveShell shell = createHiveCliShell(); shell.start(); String statement = "select current_database(), NULL, 100"; when(container.executeStatement(statement)).thenReturn(Arrays.<Object[]> asList( new Object[] {"default", null, 100})); String hiveSql = statement + ";"; File file = tempFolder.newFile("script.sql"); Files.write(hiveSql, file, UTF_8); List<String> results = shell.executeQuery(UTF_8, Paths.get(file.toURI()), "xxx", "yyy"); assertThat(results.size(), is(1)); assertThat(results.get(0), is("defaultxxxyyyxxx100")); }
Example #5
Source File: MavenImportUtils.java From sarl with Apache License 2.0 | 6 votes |
/** Force the pom file of a project to be "simple". * * @param projectDir the folder in which the pom file is located. * @param monitor the progress monitor. * @throws IOException if the pom file cannot be changed. */ static void forceSimplePom(File projectDir, IProgressMonitor monitor) throws IOException { final File pomFile = new File(projectDir, POM_FILE); if (pomFile.exists()) { final SubMonitor submon = SubMonitor.convert(monitor, 4); final File savedPomFile = new File(projectDir, POM_BACKUP_FILE); if (savedPomFile.exists()) { savedPomFile.delete(); } submon.worked(1); Files.copy(pomFile, savedPomFile); submon.worked(1); final StringBuilder content = new StringBuilder(); try (BufferedReader stream = new BufferedReader(new FileReader(pomFile))) { String line = stream.readLine(); while (line != null) { line = line.replaceAll("<extensions>\\s*true\\s*</extensions>", ""); //$NON-NLS-1$ //$NON-NLS-2$ content.append(line).append("\n"); //$NON-NLS-1$ line = stream.readLine(); } } submon.worked(1); Files.write(content.toString().getBytes(), pomFile); submon.worked(1); } }
Example #6
Source File: Packager.java From javaide with GNU General Public License v3.0 | 6 votes |
private void doAddFile(File file, String archivePath) throws IZipEntryFilter.ZipAbortException, IOException { // If a file has to be merged, write it to a file in the merging folder and add it later. if (mMergeFiles.keySet().contains(archivePath)) { File mergingFile = mMergeFiles.get(archivePath); Files.createParentDirs(mergingFile); FileOutputStream fos = new FileOutputStream(mMergeFiles.get(archivePath), true); try { fos.write(Files.toByteArray(file)); } finally { fos.close(); } } else { if (!mNoBinaryZipFilter.checkEntry(archivePath)) { return; } mAddedFiles.put(archivePath, file); mBuilder.writeFile(file, archivePath); } }
Example #7
Source File: BindataToZK.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { File file = new File(SystemConfig.getHomePath()+ "/conf","ruledata" ); if(file.exists()&&file.isDirectory()) { File[] binFiles=file.listFiles(); for (File binFile : binFiles) { String path= ZKUtils.getZKBasePath()+"ruledata/"+binFile.getName(); CuratorFramework zk= ZKUtils.getConnection(); try { zk.create().creatingParentsIfNeeded().forPath(path) ; zk.setData().forPath(path, Files.toByteArray(binFile)) ; } catch (Exception e) { e.printStackTrace(); } } } }
Example #8
Source File: CheBootstrap.java From che with Eclipse Public License 2.0 | 6 votes |
protected void bindConf(File confDir) { final File[] files = confDir.listFiles(); if (files != null) { for (File file : files) { if (!file.isDirectory()) { if ("properties".equals(Files.getFileExtension(file.getName()))) { Properties properties = new Properties(); try (Reader reader = Files.newReader(file, Charset.forName("UTF-8"))) { properties.load(reader); } catch (IOException e) { throw new IllegalStateException( format("Unable to read configuration file %s", file), e); } bindProperties(properties); } } } } }
Example #9
Source File: FileUtils.java From AnoleFix with MIT License | 6 votes |
/** * Chooses a directory name, based on a JAR file name, considering exploded-aar and classes.jar. */ public static String getDirectoryNameForJar(File inputFile) { // add a hash of the original file path. HashFunction hashFunction = Hashing.sha1(); HashCode hashCode = hashFunction.hashString(inputFile.getAbsolutePath(), Charsets.UTF_16LE); String name = Files.getNameWithoutExtension(inputFile.getName()); if (name.equals("classes") && inputFile.getAbsolutePath().contains("exploded-aar")) { // This naming scheme is coming from DependencyManager#computeArtifactPath. File versionDir = inputFile.getParentFile().getParentFile(); File artifactDir = versionDir.getParentFile(); File groupDir = artifactDir.getParentFile(); name = Joiner.on('-').join( groupDir.getName(), artifactDir.getName(), versionDir.getName()); } name = name + "_" + hashCode.toString(); return name; }
Example #10
Source File: TestRemoteDownloadSource.java From datacollector with Apache License 2.0 | 6 votes |
private void testPathInUri(boolean userDirisRoot) throws Exception { String originPath = currentThread().getContextClassLoader().getResource("remote-download-source/parseNoError").getPath(); File originDirFile = new File(originPath).listFiles()[0]; File tempDir = testFolder.newFolder(); File copied = new File(tempDir, originDirFile.getName()); Files.copy(originDirFile, copied); setupServer(testFolder.getRoot().getAbsolutePath(), true); String pathInUri = userDirisRoot ? tempDir.getName() : tempDir.getAbsolutePath(); RemoteDownloadSource origin = new TestRemoteDownloadSourceBuilder(scheme, port) .withRemoteHost(scheme.name() + "://localhost:" + port + "/" + pathInUri) .withUserDirIsRoot(userDirisRoot) .build(); SourceRunner runner = new SourceRunner.Builder(RemoteDownloadDSource.class, origin) .addOutputLane("lane") .build(); runner.runInit(); StageRunner.Output op = runner.runProduce(RemoteDownloadSource.NOTHING_READ, 1000); List<Record> expected = getExpectedRecords(); List<Record> actual = op.getRecords().get("lane"); Assert.assertEquals(expected.size(), actual.size()); for (int i = 0; i < 2; i++) { Assert.assertEquals(expected.get(i).get(), actual.get(i).get()); } destroyAndValidate(runner); }
Example #11
Source File: TestProdTypePatternMetExtractor.java From oodt with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { URL url = getClass().getResource("/product-type-patterns.xml"); configFile = new File(url.toURI()); extractor = new ProdTypePatternMetExtractor(); extractor.setConfigFile(configFile); tmpDir = Files.createTempDir(); book1 = new File(tmpDir, "book-1234567890.txt"); book2 = new File(tmpDir, "book-0987654321.txt"); page1 = new File(tmpDir, "page-1234567890-111.txt"); page2 = new File(tmpDir, "page-0987654321-222.txt"); Files.touch(book1); Files.touch(book2); Files.touch(page1); Files.touch(page2); url = getClass().getResource("/product-type-patterns-2.xml"); configFile2 = new File(url.toURI()); page1a = new File(tmpDir, "page-111-1234567890.txt"); page2a = new File(tmpDir, "page-222-0987654321.txt"); Files.touch(page1a); Files.touch(page2a); }
Example #12
Source File: DataLoader.java From gadgetinspector with MIT License | 6 votes |
public static <T> void saveData(Path filePath, DataFactory<T> factory, Collection<T> values) throws IOException { try (BufferedWriter writer = Files.newWriter(filePath.toFile(), StandardCharsets.UTF_8)) { for (T value : values) { final String[] fields = factory.serialize(value); if (fields == null) { continue; } StringBuilder sb = new StringBuilder(); for (String field : fields) { if (field == null) { sb.append("\t"); } else { sb.append("\t").append(field); } } writer.write(sb.substring(1)); writer.write("\n"); } } }
Example #13
Source File: CheBootstrap.java From che with Eclipse Public License 2.0 | 6 votes |
private Map<String, Set<String>> readConfigurationAliases() { URL aliasesResource = getClass().getClassLoader().getResource(PROPERTIES_ALIASES_CONFIG_FILE); Map<String, Set<String>> aliases = new HashMap<>(); if (aliasesResource != null) { Properties properties = new Properties(); File aliasesFile = new File(aliasesResource.getFile()); try (Reader reader = Files.newReader(aliasesFile, Charset.forName("UTF-8"))) { properties.load(reader); } catch (IOException e) { throw new IllegalStateException( format("Unable to read configuration aliases from file %s", aliasesFile), e); } for (Map.Entry<Object, Object> entry : properties.entrySet()) { String value = (String) entry.getValue(); aliases.put( (String) entry.getKey(), Splitter.on(',').splitToList(value).stream().map(String::trim).collect(toSet())); } } return aliases; }
Example #14
Source File: FilePersister.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public void persist(Date date, PerformanceTestDescriptor options, PerformanceTestResult result) { try { String dateStr = new SimpleDateFormat(Time.DATE_FORMAT_PREFERRED).format(date); dir.mkdirs(); File file = new File(dir, "auto-test-results.txt"); file.createNewFile(); Files.append("date="+dateStr+"; test="+options+"; result="+result+"\n", file, Charsets.UTF_8); File summaryFile = new File(dir, "auto-test-summary.txt"); summaryFile.createNewFile(); Files.append( dateStr +"\t"+options.summary +"\t"+roundToSignificantFigures(result.ratePerSecond, 6) +"\t"+result.duration +(result.cpuTotalFraction != null ? "\t"+"cpu="+roundToSignificantFigures(result.cpuTotalFraction, 3) : "") +"\n", summaryFile, Charsets.UTF_8); } catch (IOException e) { LOG.warn("Failed to persist performance results to "+dir+" (continuing)", e); } }
Example #15
Source File: ComponentDatabaseTest.java From appinventor-extensions with Apache License 2.0 | 6 votes |
/** * Checks whether the component database was correctly initialized. */ public void testComponentDatabase() throws IOException { // Load component descriptor file String componentDescriptorSource = Files.toString( new File(TestUtils.APP_INVENTOR_ROOT_DIR + COMPONENT_DESCRIPTOR_FILE), Charset.forName("UTF8")); // Parse the data file and check the existence of some key components final ComponentDatabase componentDatabase = new ComponentDatabase( new ServerJsonParser().parse(componentDescriptorSource).asArray()); Set<String> components = componentDatabase.getComponentNames(); assertTrue(components.contains("Button")); assertTrue(components.contains("Label")); assertTrue(components.contains("TextBox")); // Check some properties defined for the TextBox component List<PropertyDefinition> properties = componentDatabase.getPropertyDefinitions("TextBox"); assertEquals("boolean", find(properties, "Enabled").getEditorType()); assertEquals("non_negative_float", find(properties, "FontSize").getEditorType()); assertEquals("string", find(properties, "Hint").getEditorType()); }
Example #16
Source File: TestCopyCommandCluster.java From kite with Apache License 2.0 | 6 votes |
@BeforeClass public static void createSourceDataset() throws Exception { repoUri = "hdfs://" + getDFS().getUri().getAuthority() + "/tmp/data"; TestUtil.run("delete", source, "-r", repoUri, "-d", "target/data"); String csv = "/tmp/users.csv"; BufferedWriter writer = Files.newWriter( new File(csv), CSVSchemaCommand.SCHEMA_CHARSET); writer.append("id,username,email\n"); writer.append("1,test,[email protected]\n"); writer.append("2,user,[email protected]\n"); writer.append("3,user3,[email protected]\n"); writer.append("4,user4,[email protected]\n"); writer.append("5,user5,[email protected]\n"); writer.append("6,user6,[email protected]\n"); writer.close(); TestUtil.run("-v", "csv-schema", csv, "-o", avsc, "--class", "User", "--require", "id"); TestUtil.run("create", source, "-s", avsc, "-r", repoUri, "-d", "target/data"); TestUtil.run("csv-import", csv, source, "-r", repoUri, "-d", "target/data"); }
Example #17
Source File: TestLinker.java From tracingplane-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Test public void testFullyQualifiedUserDefinedImport() throws CompileException, IOException { File dir = Files.createTempDir(); dir.deleteOnExit(); File f1 = new File(dir, "bagpathimport"); File f2 = createFile(); write(f1, "package edu.brown.cs;\nbag MyBag1 {bool test = 0;}"); write(f2, "import \"%s\";\nbag MyBag2 {edu.brown.cs.MyBag1 test = 0;}", f1.getName()); List<String> inputFiles = Lists.newArrayList(f2.getAbsolutePath()); List<String> bagPath = Lists.newArrayList(dir.getAbsolutePath()); Linker.link(inputFiles, bagPath); }
Example #18
Source File: SequenceTopropertiesLoader.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
/** * 读取 mapFile文件的信息 * 方法描述 * @param name 名称信息 * @return * @创建日期 2016年9月18日 */ private void writeMapFile(String name, String value) { // 加载数据 String path = RuleszkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) .getPath(); checkNotNull(path, "write Map file curr Path :" + path + " is null! must is not null"); path = new File(path).getPath() + File.separator; path += name; // 进行数据写入 try { Files.write(value.getBytes(), new File(path)); } catch (IOException e1) { e1.printStackTrace(); } }
Example #19
Source File: TypeMetadataTest.java From datawave with Apache License 2.0 | 6 votes |
@Test public void testFileRoundTrip() throws Exception { Map<String,TypeMetadata> map = prepareTypeMetadataMap(); final File tempDir = Files.createTempDir(); tempDir.deleteOnExit(); final File tempFile = new File(tempDir, "type_metadata_roundtrip_test"); FileOutputStream fos = new FileOutputStream(tempFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(map); oos.close(); FileInputStream fis = new FileInputStream(tempFile); ObjectInputStream ois = new ObjectInputStream(fis); Object got = ois.readObject(); Assert.assertEquals(got, map); }
Example #20
Source File: TestCDep.java From cdep with Apache License 2.0 | 6 votes |
@Test public void download() throws Exception { CDepYml config = new CDepYml(); File yaml = new File(".test-files/download/cdep.yml"); yaml.getParentFile().mkdirs(); Files.write("builders: [cmake, cmakeExamples]\n" + "dependencies:\n" + "- compile: com.github.jomof:low-level-statistics:0.0.16\n", yaml, StandardCharsets.UTF_8); // Download first. main("-wf", yaml.getParent()); // Redownload String result = main("download", "-wf", yaml.getParent()); System.out.printf(result); assertThat(result).doesNotContain("Redownload"); assertThat(result).contains("Generating"); }
Example #21
Source File: WriterOutputFormatIntegrationTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
private Properties getProperties() throws IOException { Properties jobProperties = GobblinLocalJobLauncherUtils.getJobProperties("runtime_test/writer_output_format_test.properties"); URL resource = getClass().getClassLoader().getResource("runtime_test/" + SAMPLE_FILE); Assert.assertNotNull(resource, "Sample file should be present"); File sampleFile = new File(resource.getFile()); File testFile = File.createTempFile("writerTest", ".avro"); FileUtils.copyFile(sampleFile, testFile); jobProperties.setProperty(ConfigurationKeys.SOURCE_FILEBASED_FILES_TO_PULL, testFile.getAbsolutePath()); String outputRootDirectory = Files.createTempDir().getAbsolutePath() + "/"; jobProperties.setProperty(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, outputRootDirectory + "state_store"); jobProperties.setProperty(ConfigurationKeys.WRITER_STAGING_DIR, outputRootDirectory + "writer_staging"); jobProperties.setProperty(ConfigurationKeys.WRITER_OUTPUT_DIR, outputRootDirectory + "writer_output"); jobProperties.setProperty(ConfigurationKeys.DATA_PUBLISHER_FINAL_DIR, outputRootDirectory + "final_dir"); return jobProperties; }
Example #22
Source File: HighLevelConsumerTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
public static Config getSimpleConfig(Optional<String> prefix) { Properties properties = new Properties(); properties.put(getConfigKey(prefix, ConfigurationKeys.KAFKA_BROKERS), "127.0.0.1:" + TestUtils.findFreePort()); properties.put(getConfigKey(prefix, Kafka09ConsumerClient.GOBBLIN_CONFIG_VALUE_DESERIALIZER_CLASS_KEY), Kafka09ConsumerClient.KAFKA_09_DEFAULT_KEY_DESERIALIZER); properties.put(getConfigKey(prefix, "zookeeper.connect"), "zookeeper"); properties.put(ConfigurationKeys.STATE_STORE_ENABLED, "true"); File tmpDir = Files.createTempDir(); tmpDir.deleteOnExit(); properties.put(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, tmpDir.toString()); return ConfigFactory.parseProperties(properties); }
Example #23
Source File: LuceneSearchTest.java From zeppelin with Apache License 2.0 | 5 votes |
@Before public void startUp() throws IOException { indexDir = Files.createTempDir().getAbsoluteFile(); System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SEARCH_INDEX_PATH.getVarName(), indexDir.getAbsolutePath()); noteSearchService = new LuceneSearch(ZeppelinConfiguration.create()); interpreterSettingManager = mock(InterpreterSettingManager.class); InterpreterSetting defaultInterpreterSetting = mock(InterpreterSetting.class); when(defaultInterpreterSetting.getName()).thenReturn("test"); when(interpreterSettingManager.getDefaultInterpreterSetting()).thenReturn(defaultInterpreterSetting); notebook = new Notebook(ZeppelinConfiguration.create(), mock(AuthorizationService.class), mock(NotebookRepo.class), mock(NoteManager.class), mock(InterpreterFactory.class), interpreterSettingManager, noteSearchService, mock(Credentials.class), null); }
Example #24
Source File: ClassfileMatchers.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public final boolean matches(Object item) { File file = (File) item; try (InputStream is = Files.asByteSource(file).openBufferedStream()) { T visitor = newClassVisitor(); new ClassReader(is).accept(visitor, 0); return matches(visitor); } catch (IOException e) { throw new RuntimeException(e); } }
Example #25
Source File: JarArtifactHandlerImpl.java From azure-gradle-plugins with MIT License | 5 votes |
protected void prepareDeploymentFiles(File jar) throws IOException { final File parent = new File(getDeploymentStagingDirectoryPath()); parent.mkdirs(); if (AppServiceType.LINUX.equals(task.getAzureWebAppExtension().getAppService().getType())) { Files.copy(jar, new File(parent, DEFAULT_LINUX_JAR_NAME)); } else { Files.copy(jar, new File(parent, jar.getName())); generateWebConfigFile(jar.getName()); } }
Example #26
Source File: RebindPolicyPrivateConstructorTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected void addMemento(BrooklynObjectType type, String label, String id) throws Exception { String mementoFilename = label+"-"+id; String memento = Streams.readFullyString(getClass().getResourceAsStream(mementoFilename)); File persistedFile = getPersistanceFile(type, id); Files.write(memento.getBytes(), persistedFile); }
Example #27
Source File: FileSerializationBenchmark.java From imhotep with Apache License 2.0 | 5 votes |
@Override public int[] deserialize(File file) throws IOException { MappedByteBuffer buffer = Files.map(file, FileChannel.MapMode.READ_ONLY, file.length()); buffer.order(ByteOrder.BIG_ENDIAN); IntBuffer intBuffer = buffer.asIntBuffer(); int[] ret = new int[(int)(file.length() / 4)]; intBuffer.get(ret); return ret; }
Example #28
Source File: ManifestHandler.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
public void loadNewInternalManifest(String... categories) { Map<String, ModContainer> modList = Loader.instance().getIndexedModList(); for (Map.Entry<String, ModContainer> entry : modList.entrySet()) { for (String category : categories) { try { for (String fileName : ManaRecipes.getResourceListing(entry.getKey(), category)) { if (fileName.isEmpty()) continue; InputStream stream = LibrarianLib.PROXY.getResource(entry.getKey(), category + "/" + fileName); if (stream == null) { Wizardry.LOGGER.error(" > SOMETHING WENT WRONG! Could not read " + fileName + " in " + category + " from mod jar! Report this to the devs on Github!"); continue; } try (BufferedReader br = new BufferedReader(new InputStreamReader(stream, Charset.defaultCharset()))) { StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } addItemToManifest(category, entry.getKey(), Files.getNameWithoutExtension(fileName), sb.toString().hashCode() + ""); } } } catch (IOException e) { e.printStackTrace(); } } } }
Example #29
Source File: JobEmailNotification.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
private String getBody() throws IOException { String jobID = jobState.getId().value(); String status = jobState.getStatus().toString(); String hostname = "UNKNOWN"; List<TaskState> tasks = jobState.getTasks(); String allTaskStatusesString = String.join(System.lineSeparator(), tasks.stream() .map(task -> task.getId().getReadableName() + " (" + task.getId().toString() + ") Status: " + task.getStatus().toString()) .collect(Collectors.toList())); try { hostname = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { logger.debug("Could not get hostname", e); } final Properties properties = EmailConfiguration.getConfiguration().getProperties(); String templatePath = properties.getProperty(EmailConfiguration.TEMPLATE_PATH); String bodyTemplate = Files.toString(new File(PASchedulerProperties.getAbsolutePath(templatePath)), Charset.defaultCharset()); Map<String, String> values = new HashMap<>(); values.put("JOB_ID", jobID); values.put("JOB_STATUS", status); values.put("JOB_TASKS", allTaskStatusesString); values.put("HOST_NAME", hostname); // use of StrSubstitutor to replace email template parameters by job details String emailBody = StrSubstitutor.replace(bodyTemplate, values, "%", "%"); return emailBody; }
Example #30
Source File: ProcessingFileExistsPredicateTest.java From kafka-connect-spooldir with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException { File processingFlag = InputFileDequeue.processingFile(EXTENSION, this.inputFile); Files.touch(processingFlag); assertFalse(this.predicate.test(this.inputFile)); processingFlag.delete(); assertTrue(this.predicate.test(this.inputFile)); }