本文整理汇总了Java中org.apache.metamodel.util.FileHelper类的典型用法代码示例。如果您正苦于以下问题:Java FileHelper类的具体用法?Java FileHelper怎么用?Java FileHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileHelper类属于org.apache.metamodel.util包,在下文中一共展示了FileHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testWriteAndReadAllStringPatterns
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
@Test
public void testWriteAndReadAllStringPatterns() throws Exception {
configurationWriter.externalize(new SimpleStringPattern("simple sp", "[email protected]"));
configurationWriter.externalize(new RegexStringPattern("regex pattern", ".*", false));
final String str = transform(configurationWriter.getDocument());
final File file = new File("target/" + getClass().getSimpleName() + "-" + testName.getMethodName() + ".xml");
FileHelper.writeStringAsFile(file, str);
final DataCleanerConfiguration configuration = new JaxbConfigurationReader().create(file);
assertEquals("[regex pattern, simple sp]",
Arrays.toString(configuration.getReferenceDataCatalog().getStringPatternNames()));
final SimpleStringPattern simpleStringPattern =
(SimpleStringPattern) configuration.getReferenceDataCatalog().getStringPattern("simple sp");
assertEquals("[email protected]", simpleStringPattern.getExpression());
final RegexStringPattern regexStringPattern =
(RegexStringPattern) configuration.getReferenceDataCatalog().getStringPattern("regex pattern");
assertEquals(".*", regexStringPattern.getExpression());
assertEquals(false, regexStringPattern.isMatchEntireString());
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:23,代码来源:DomConfigurationWriterTest.java
示例2: getSampleBuffer
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
protected byte[] getSampleBuffer() {
byte[] bytes = new byte[SAMPLE_BUFFER_SIZE];
final InputStream inputStream = _resource.read();
try {
final int bufferSize = inputStream.read(bytes, 0, SAMPLE_BUFFER_SIZE);
if (bufferSize != -1 && bufferSize != SAMPLE_BUFFER_SIZE) {
bytes = Arrays.copyOf(bytes, bufferSize);
}
return bytes;
} catch (final IOException e) {
logger.error("IOException occurred while reading sample buffer", e);
return new byte[0];
} finally {
FileHelper.safeClose(inputStream);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:17,代码来源:CsvConfigurationDetection.java
示例3: load
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public static final DataCleanerSpoonConfiguration load() throws DataCleanerSpoonConfigurationException {
final String pluginFolderPath = detectPluginFolderPath();
final String configurationFilePath = pluginFolderPath + "/" + CONFIGURATION_FILENAME;
final File file = new File(configurationFilePath);
if (!file.exists()) {
throw new DataCleanerSpoonConfigurationException("No configuration file: " + configurationFilePath + ". Please set DataCleaner configuration from the Tools menu.");
}
final String installationPath = FileHelper.readFileAsString(file);
if (installationPath == null || installationPath.trim().isEmpty()) {
throw new DataCleanerSpoonConfigurationException("Configuration file is empty: " + configurationFilePath +". Please set DataCleaner configuration from the Tools menu.");
}
final DataCleanerSpoonConfiguration configuration = new DataCleanerSpoonConfiguration(pluginFolderPath,
installationPath);
return configuration;
}
开发者ID:datacleaner,项目名称:pdi-datacleaner,代码行数:19,代码来源:DataCleanerSpoonConfiguration.java
示例4: copyFileToHdfs
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public URI copyFileToHdfs(final File file, final String hdfsPath, final boolean overwrite) {
final HdfsResource hdfsResource = createResource(hdfsPath);
final URI uri = hdfsResource.getHadoopPath().toUri();
final boolean exists = hdfsResource.isExists();
if (!overwrite && exists) {
// no need to copy
logger.debug("Skipping file-copy to {} because file already exists", hdfsPath);
return uri;
}
if (exists) {
logger.info("Overwriting file on HDFS: {}", hdfsPath);
} else {
logger.debug("Copying file to HDFS: {}", hdfsPath);
}
hdfsResource.write(out -> {
final FileInputStream in = new FileInputStream(file);
FileHelper.copy(in, out);
in.close();
});
return uri;
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:25,代码来源:ApplicationDriver.java
示例5: readJob
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public AnalysisJob readJob(final HttpServletRequest request) throws IOException {
final JaxbJobReader reader = new JaxbJobReader(_configuration);
final String jobDefinition = request.getParameter(HttpClusterManager.HTTP_PARAM_JOB_DEF);
final InputStream inputStream;
if (jobDefinition == null) {
// backwards compatibility node
inputStream = request.getInputStream();
} else {
inputStream = new ByteArrayInputStream(jobDefinition.getBytes());
}
try {
final AnalysisJobBuilder jobBuilder = reader.create(inputStream);
if (_jobInterceptor != null) {
_jobInterceptor.intercept(jobBuilder, _configuration);
}
return jobBuilder.toAnalysisJob();
} finally {
FileHelper.safeClose(inputStream);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:23,代码来源:SlaveServletHelper.java
示例6: determineVersionFromMavenProperties
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
private static String determineVersionFromMavenProperties(final String groupId, final String artifactId,
final String valueIfNull) {
final Properties properties = new Properties();
final String resourcePath = "/META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties";
final InputStream inputStream = Version.class.getResourceAsStream(resourcePath);
try {
properties.load(inputStream);
} catch (final Exception e) {
// do nothing
System.err.println("Failed to load DataCleaner version from manifest: " + e.getMessage());
return valueIfNull;
} finally {
FileHelper.safeClose(inputStream);
}
return properties.getProperty("version", valueIfNull);
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:18,代码来源:Version.java
示例7: testNoPatterns
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public void testNoPatterns() throws Exception {
InputColumn<String> col1 = new MockInputColumn<String>("email username", String.class);
PatternFinderAnalyzer analyzer = new PatternFinderAnalyzer();
analyzer.setColumn(col1);
analyzer.setRowAnnotationFactory(new InMemoryRowAnnotationFactory());
analyzer.init();
PatternFinderResult result = analyzer.getResult();
HtmlFragment htmlFragment = new PatternFinderResultHtmlRenderer(rendererFactory).render(result);
htmlFragment.initialize(context);
assertEquals(0, htmlFragment.getHeadElements().size());
assertEquals(1, htmlFragment.getBodyElements().size());
String html = htmlFragment.getBodyElements().get(0).toHtml(context);
assertEquals(FileHelper.readFileAsString(new File(
"src/test/resources/pattern_finder_result_html_renderer_empty.html")), html);
}
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:20,代码来源:PatternFinderResultHtmlRendererTest.java
示例8: saveOrThrow
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
private static void saveOrThrow(final AnalysisResult analysisResult, final Resource resource) {
final SimpleAnalysisResult simpleAnalysisResult;
if (analysisResult instanceof SimpleAnalysisResult) {
simpleAnalysisResult = (SimpleAnalysisResult) analysisResult;
} else {
simpleAnalysisResult =
new SimpleAnalysisResult(analysisResult.getResultMap(), analysisResult.getCreationDate());
}
final OutputStream out = resource.write();
try {
SerializationUtils.serialize(simpleAnalysisResult, out);
} catch (final SerializationException e) {
logger.error("Error serializing analysis result: " + analysisResult, e);
throw e;
} finally {
FileHelper.safeClose(out);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:20,代码来源:AnalysisResultSaveHandler.java
示例9: testChangesInbetweenUsage
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public void testChangesInbetweenUsage() throws Exception {
final File file = new File("target/TextBasedDictionaryTest-modification.txt");
FileHelper.writeStringAsFile(file, "foo\nbar");
final TextFileDictionary dict = new TextFileDictionary("dict", file.getPath(), "UTF-8");
try (DictionaryConnection connection = dict.openConnection(configuration)) {
assertTrue(connection.containsValue("foo"));
assertTrue(connection.containsValue("bar"));
assertFalse(connection.containsValue("foobar"));
}
FileHelper.writeStringAsFile(file, "foo\nfoobar");
try (DictionaryConnection connection = dict.openConnection(configuration)) {
assertTrue(connection.containsValue("foo"));
assertFalse(connection.containsValue("bar"));
assertTrue(connection.containsValue("foobar"));
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:20,代码来源:TextFileDictionaryTest.java
示例10: testModificationsClearCache
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public void testModificationsClearCache() throws Exception {
final File file = new File("target/TextBasedSynonymCatalogTest-modification.txt");
FileHelper.writeStringAsFile(file, "foo,fooo,fo\nbar,baar,br", "UTF-8");
final SynonymCatalog cat = new TextFileSynonymCatalog("sc", file, true, "UTF-8");
try (SynonymCatalogConnection scConnection = cat.openConnection(configuration)) {
assertEquals("foo", scConnection.getMasterTerm("fooo"));
assertEquals("bar", scConnection.getMasterTerm("br"));
assertEquals(null, scConnection.getMasterTerm("foob"));
}
FileHelper.writeStringAsFile(file, "foo,fooo,fo\nfoobar,foob");
try (SynonymCatalogConnection scConnection = cat.openConnection(configuration)) {
assertEquals("foo", scConnection.getMasterTerm("fooo"));
assertEquals(null, scConnection.getMasterTerm("br"));
assertEquals("foobar", scConnection.getMasterTerm("foob"));
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:20,代码来源:TextFileSynonymCatalogTest.java
示例11: createFont
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
private static Font createFont(final String path) {
final URL url = ResourceManager.get().getUrl(path);
if (url == null) {
throw new IllegalArgumentException("Font resource not found: " + path);
}
InputStream in = null;
try {
in = url.openStream();
return Font.createFont(Font.TRUETYPE_FONT, in);
} catch (final Exception e) {
throw new IllegalStateException(e);
} finally {
FileHelper.safeClose(in);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:17,代码来源:WidgetUtils.java
示例12: save
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
@Override
public void save() {
if (_userPreferencesFile == null) {
logger.debug("Not saving user preferences, since no user preferences file has been provided");
return;
}
logger.info("Saving user preferences to {}", _userPreferencesFile.getName().getPath());
ObjectOutputStream outputStream = null;
try {
final OutputStream fileOutputStream = _userPreferencesFile.getContent().getOutputStream();
outputStream = new ObjectOutputStream(fileOutputStream);
outputStream.writeObject(this);
outputStream.flush();
} catch (final Exception e) {
logger.warn("Unexpected error while saving user preferences", e);
throw new IllegalStateException(e);
} finally {
FileHelper.safeClose(outputStream);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:23,代码来源:UserPreferencesImpl.java
示例13: getSampleBuffer
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
protected byte[] getSampleBuffer() {
byte[] bytes = new byte[SAMPLE_BUFFER_SIZE];
final Resource resource = getResource();
final InputStream in = resource.read();
try {
final int bufferSize = in.read(bytes, 0, SAMPLE_BUFFER_SIZE);
if (bufferSize != -1 && bufferSize != SAMPLE_BUFFER_SIZE) {
bytes = Arrays.copyOf(bytes, bufferSize);
}
return bytes;
} catch (final IOException e) {
logger.error("IOException occurred while reading sample buffer", e);
return new byte[0];
} finally {
FileHelper.safeClose(in);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:19,代码来源:AbstractResourceBasedDatastoreDialog.java
示例14: getSampleBuffer
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
protected byte[] getSampleBuffer() {
final File file = new File(getFilename());
byte[] bytes = new byte[SAMPLE_BUFFER_SIZE];
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
final int bufferSize = fileInputStream.read(bytes, 0, SAMPLE_BUFFER_SIZE);
if (bufferSize != -1 && bufferSize != SAMPLE_BUFFER_SIZE) {
bytes = Arrays.copyOf(bytes, bufferSize);
}
return bytes;
} catch (final IOException e) {
logger.error("IOException occurred while reading sample buffer", e);
return new byte[0];
} finally {
FileHelper.safeClose(fileInputStream);
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:19,代码来源:AbstractFileBasedDatastoreDialog.java
示例15: testSinglePatterns
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public void testSinglePatterns() throws Exception {
InputColumn<String> col1 = new MockInputColumn<String>("email username", String.class);
PatternFinderAnalyzer analyzer = new PatternFinderAnalyzer();
analyzer.setColumn(col1);
analyzer.setRowAnnotationFactory(new InMemoryRowAnnotationFactory());
analyzer.init();
analyzer.run(new MockInputRow().put(col1, "kasper"), 1);
analyzer.run(new MockInputRow().put(col1, "kasper.sorensen"), 1);
analyzer.run(new MockInputRow().put(col1, "info"), 1);
analyzer.run(new MockInputRow().put(col1, "kasper.sorensen"), 1);
analyzer.run(new MockInputRow().put(col1, "winfried.vanholland"), 1);
analyzer.run(new MockInputRow().put(col1, "kaspers"), 1);
PatternFinderResult result = analyzer.getResult();
HtmlFragment htmlFragment = new PatternFinderResultHtmlRenderer(rendererFactory).render(result);
htmlFragment.initialize(context);
assertEquals(0, htmlFragment.getHeadElements().size());
assertEquals(1, htmlFragment.getBodyElements().size());
String html = htmlFragment.getBodyElements().get(0).toHtml(context);
assertEquals(FileHelper.readFileAsString(new File(
"src/test/resources/pattern_finder_result_html_renderer_single.html")), html);
}
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:27,代码来源:PatternFinderResultHtmlRendererTest.java
示例16: runBenchmarkTest
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
private void runBenchmarkTest(final ComponentDescriptor<?> descriptor, final File benchmarkFile,
final File outputFile) throws Exception {
documentationCreator.write(descriptor, new FileOutputStream(outputFile));
final String output = normalize(FileHelper.readFileAsString(outputFile));
final String benchmark;
if (benchmarkFile.exists()) {
benchmark = normalize(FileHelper.readFileAsString(benchmarkFile));
} else {
// use path to make it simple to add the benchmark file when it
// breaks
benchmark = "No such file: " + benchmarkFile.getPath();
}
// uncomment the following line to bulk-update the benchmark files
// FileHelper.writeStringAsFile(benchmarkFile, output);
assertEquals(benchmark, output);
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:21,代码来源:ComponentDocumentationBuilderTest.java
示例17: generateCoreFile
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public void generateCoreFile() throws IOException {
final File coreSiteFile = new File(confFolder, "conf-site.xml");
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("core-site-template.xml")) {
final BufferedReader reader = FileHelper.getBufferedReader(inputStream, FileHelper.UTF_8_ENCODING);
try (Writer writer = FileHelper.getWriter(coreSiteFile)) {
String line = reader.readLine();
while (line != null) {
line = line.replace("${PATH}", path);
writer.write(line);
line = reader.readLine();
}
writer.flush();
}
}
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:17,代码来源:MockHadoopConfigHelper.java
示例18: testModificationsClearCache
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
public void testModificationsClearCache() throws Exception {
File file = new File("target/TextBasedDictionaryTest-modification.txt");
FileHelper.writeStringAsFile(file, "foo\nbar");
TextFileDictionary dict = new TextFileDictionary("dict", file.getPath(), "UTF-8");
dict.init();
assertTrue(dict.containsValue("foo"));
assertTrue(dict.containsValue("bar"));
assertFalse(dict.containsValue("foobar"));
// sleep to make sure the file monitor will catch a file change
Thread.sleep(2000);
FileHelper.writeStringAsFile(file, "foo\nfoobar");
dict.init();
assertTrue(dict.containsValue("foo"));
assertFalse(dict.containsValue("bar"));
assertTrue(dict.containsValue("foobar"));
}
开发者ID:datacleaner,项目名称:AnalyzerBeans,代码行数:21,代码来源:TextFileDictionaryTest.java
示例19: writeAndCompareWithBenchmark
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
private void writeAndCompareWithBenchmark(final AnalysisResult analysisResult,
final DataCleanerConfigurationImpl configuration) throws IOException {
final HtmlAnalysisResultWriter writer = new HtmlAnalysisResultWriter();
final StringWriter stringWriter = new StringWriter();
writer.write(analysisResult, configuration, stringWriter);
final String actual = stringWriter.toString();
final File benchmarkFile = new File(
"src/test/resources/benchmark-renderings/" + getClass().getSimpleName() + "-" + testName.getMethodName()
+ ".html");
if (!benchmarkFile.exists()) {
Assert.assertEquals("File does not exist: " + benchmarkFile, actual);
}
final String expected = FileHelper.readFileAsString(benchmarkFile);
Assert.assertEquals(expected.replaceAll("\r\n", "\n"), actual.replaceAll("\r\n", "\n"));
}
开发者ID:datacleaner,项目名称:DataCleaner,代码行数:20,代码来源:HtmlAnalysisResultWriterTest.java
示例20: materializeMainSchemaTable
import org.apache.metamodel.util.FileHelper; //导入依赖的package包/类
@Override
protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) {
DataInputStream inputStream = createInputStream();
// skip through the metadata section
try {
readMetadataSection(inputStream);
} catch (RuntimeException e) {
FileHelper.safeClose(inputStream);
throw e;
}
DataSet dataSet = new KettleDataSet(columns, inputStream, rowMeta);
if (maxRows >= 0) {
dataSet = new MaxRowsDataSet(dataSet, maxRows);
}
return dataSet;
}
开发者ID:datacleaner,项目名称:pdi-datacleaner,代码行数:19,代码来源:KettleDataContext.java
注:本文中的org.apache.metamodel.util.FileHelper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论