org.springframework.util.ResourceUtils.getFile()

Here are the examples of the java api org.springframework.util.ResourceUtils.getFile() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

144 Examples 7

19 View Source File : ConfigParser.java
License : Apache License 2.0
Project Creator : zhangjun1998

/**
 * 在IDE启动获取配置文件
 * @Description
 * @Author ZhangJun
 * @Date 13:28 2020/8/29
 * @Param
 * @return
 */
public File getProjectConfigFile() throws Exception {
    return ResourceUtils.getFile("clreplacedpath:config/zrp-server.yaml");
}

19 View Source File : DefaultScrapeManager.java
License : Apache License 2.0
Project Creator : sofastack

@Override
public List<ScrapeConfig> loadConfigFile(String configFile) throws FileNotFoundException {
    File file = ResourceUtils.getFile(configFile);
    return loadConfigFile(file);
}

19 View Source File : RegistrationControllerTest.java
License : Apache License 2.0
Project Creator : scalefocus

private String getResource(String path) throws IOException {
    final File inputFile = ResourceUtils.getFile(path);
    return Files.lines(inputFile.toPath()).collect(Collectors.joining());
}

19 View Source File : WorkflowSpecificationsHandlerTest.java
License : Apache License 2.0
Project Creator : onap

private String getWiremockResponseForCatalogdb(String file) {
    try {
        File resource = ResourceUtils.getFile("clreplacedpath:__files/catalogdb/" + file);
        return new String(Files.readAllBytes(resource.toPath())).replaceAll("localhost:8090", "localhost:" + wiremockPort);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}

19 View Source File : WebController.java
License : GNU General Public License v3.0
Project Creator : luoye663

@RequestMapping("getAnnouncement")
public String getAnnouncement() throws IOException {
    String s = StringUtil.readTxt(ResourceUtils.getFile("clreplacedpath:announcement.txt"));
    return s;
}

19 View Source File : FileUtils.java
License : MIT License
Project Creator : ls1intum

/**
 * @param path path relative to the test resources folder complaint
 * @return string representation of given file
 * @throws IOException if the resource cannot be loaded
 */
public static String loadFileFromResources(String path) throws IOException {
    java.io.File file = ResourceUtils.getFile("clreplacedpath:" + path);
    StringBuilder builder = new StringBuilder();
    Files.lines(file.toPath()).forEach(builder::append);
    replacedertThat(builder.toString()).as("file has been correctly read from file").isNotEqualTo("");
    return builder.toString();
}

19 View Source File : UMLModelParserTest.java
License : MIT License
Project Creator : ls1intum

private JsonObject loadFileFromResources(String path) throws Exception {
    java.io.File file = ResourceUtils.getFile("clreplacedpath:" + path);
    StringBuilder builder = new StringBuilder();
    Files.lines(file.toPath()).forEach(builder::append);
    replacedertThat(builder.toString()).as("model has been correctly read from file").isNotEqualTo("");
    return parseString(builder.toString()).getAsJsonObject();
}

19 View Source File : MailUtil.java
License : MIT License
Project Creator : linj6

/**
 * 获取邮箱模板文件 返回模板内容
 *
 * @return
 * @throws IOException
 */
public static String getHtmlTemplateText(String templatePath, String charset) throws IOException {
    File file = ResourceUtils.getFile("clreplacedpath:" + templatePath);
    String template;
    if (StringUtils.isNotBlank(charset)) {
        template = FileUtils.readFileToString(file, charset);
    } else {
        template = FileUtils.readFileToString(file, DAFAULT_CHARSET);
    }
    return template;
}

19 View Source File : ApplicationProperties.java
License : MIT License
Project Creator : Blackdread

private String keywordsAsJson(String file) {
    try {
        Path path = ResourceUtils.getFile(file).toPath();
        return String.join(" ", Files.readAllLines(path));
    } catch (IOException e) {
        return "{\"key\": []}";
    }
}

19 View Source File : BaseConnectorTest.java
License : Apache License 2.0
Project Creator : binglind

protected String getYamlString(String filePath) throws Exception {
    File file = ResourceUtils.getFile(filePath);
    Long filelength = file.length();
    byte[] filecontent = new byte[filelength.intValue()];
    try {
        FileInputStream in = new FileInputStream(file);
        in.read(filecontent);
        in.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        return new String(filecontent, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

protected String getTestFileName(String sourceMimetype) throws FileNotFoundException {
    String extension = mimetypeMap.getExtension(sourceMimetype);
    String testFileName = extension.equals(EXTENSION_BINARY) ? null : "quick." + extension;
    if (testFileName != null) {
        try {
            ResourceUtils.getFile("clreplacedpath:quick/" + testFileName);
        } catch (FileNotFoundException e) {
            testFileName = null;
        }
    }
    return testFileName;
}

19 View Source File : BulkImportTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco

/**
 * Simplifies calling {@ResourceUtils.getFile} so that a {@link RuntimeException}
 * is thrown rather than a checked {@link FileNotFoundException} exception.
 *
 * @param resourceName e.g. "clreplacedpath:folder/file"
 * @return File object
 */
private File resourceAsFile(String resourceName) {
    try {
        return ResourceUtils.getFile(resourceName);
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Resource " + resourceName + " not found", e);
    }
}

19 View Source File : BulkImportTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco

@Test
public void testCopyImportStriping() throws Throwable {
    txn = transactionService.getUserTransaction();
    txn.begin();
    NodeRef folderNode = topLevelFolder.getNodeRef();
    try {
        NodeImporter nodeImporter = streamingNodeImporterFactory.getNodeImporter(ResourceUtils.getFile("clreplacedpath:bulkimport"));
        BulkImportParameters bulkImportParameters = new BulkImportParameters();
        bulkImportParameters.setTarget(folderNode);
        bulkImportParameters.setReplaceExisting(true);
        bulkImportParameters.setDisableRulesService(true);
        bulkImportParameters.setBatchSize(40);
        bulkImporter.bulkImport(bulkImportParameters, nodeImporter);
    } catch (Throwable e) {
        fail(e.getMessage());
    }
    System.out.println(bulkImporter.getStatus());
    checkFiles(folderNode, null, 2, 9, new ExpectedFile[] { new ExpectedFile("quickImg1.xls", MimetypeMap.MIMETYPE_EXCEL), new ExpectedFile("quickImg1.doc", MimetypeMap.MIMETYPE_WORD), new ExpectedFile("quick.txt", MimetypeMap.MIMETYPE_TEXT_PLAIN, "The quick brown fox jumps over the lazy dog") }, new ExpectedFolder[] { new ExpectedFolder("folder1"), new ExpectedFolder("folder2") });
    List<FileInfo> folders = getFolders(folderNode, "folder1");
    replacedertEquals("", 1, folders.size());
    NodeRef folder1 = folders.get(0).getNodeRef();
    checkFiles(folder1, null, 1, 0, null, new ExpectedFolder[] { new ExpectedFolder("folder1.1") });
    folders = getFolders(folderNode, "folder2");
    replacedertEquals("", 1, folders.size());
    NodeRef folder2 = folders.get(0).getNodeRef();
    checkFiles(folder2, null, 1, 0, new ExpectedFile[] {}, new ExpectedFolder[] { new ExpectedFolder("folder2.1") });
    folders = getFolders(folder1, "folder1.1");
    replacedertEquals("", 1, folders.size());
    NodeRef folder1_1 = folders.get(0).getNodeRef();
    checkFiles(folder1_1, null, 2, 12, new ExpectedFile[] { new ExpectedFile("quick.txt", MimetypeMap.MIMETYPE_TEXT_PLAIN, "The quick brown fox jumps over the lazy dog"), new ExpectedFile("quick.sxw", MimetypeMap.MIMETYPE_OPENOFFICE1_WRITER), new ExpectedFile("quick.tar", "application/x-gtar") }, new ExpectedFolder[] { new ExpectedFolder("folder1.1.1"), new ExpectedFolder("folder1.1.2") });
    folders = getFolders(folder2, "folder2.1");
    replacedertEquals("", 1, folders.size());
    NodeRef folder2_1 = folders.get(0).getNodeRef();
    checkFiles(folder2_1, null, 0, 17, new ExpectedFile[] { new ExpectedFile("quick.png", MimetypeMap.MIMETYPE_IMAGE_PNG), new ExpectedFile("quick.pdf", MimetypeMap.MIMETYPE_PDF), new ExpectedFile("quick.odt", MimetypeMap.MIMETYPE_OPENDOreplacedENT_TEXT) }, new ExpectedFolder[] {});
}

19 View Source File : TxleStaticConfig.java
License : Apache License 2.0
Project Creator : actiontech

public static void initTxleStaticConfig() {
    try {
        File resourceDir = ResourceUtils.getFile(ResourceUtils.CLreplacedPATH_URL_PREFIX);
        if (resourceDir != null && resourceDir.isDirectory()) {
            File[] files = resourceDir.listFiles();
            if (files != null && files.length > 0) {
                for (File file : files) {
                    if (file.getName().endsWith(".yml") || file.getName().endsWith(".yaml")) {
                        convertYmlToMapConfig(file.getPath());
                    } else if (file.getName().endsWith(".properties")) {
                        convertPropertiesToMapConfig(file.getPath());
                    }
                }
            }
        }
    } catch (Exception e) {
        LOG.error(TxleConstants.logErrorPrefixWithTime() + "Failed to initialize the Static Configs.", e);
    }
}

18 View Source File : AbstractFileResolvingResource.java
License : MIT License
Project Creator : Vip-Augus

/**
 * This implementation returns a File reference for the given URI-identified
 * resource, provided that it refers to a file in the file system.
 * @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String)
 */
protected File getFile(URI uri) throws IOException {
    if (uri.getScheme().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
        return VfsResourceDelegate.getResource(uri).getFile();
    }
    return ResourceUtils.getFile(uri, getDescription());
}

18 View Source File : GitRepo.java
License : Apache License 2.0
Project Creator : spring-cloud

private File file(File project) throws FileNotFoundException {
    return ResourceUtils.getFile(project.toURI()).getAbsoluteFile();
}

18 View Source File : StaticTargetScrapeTest.java
License : Apache License 2.0
Project Creator : sofastack

@Test
public void testUpdateStaticTargetConfigScheduleFromPath() throws FileNotFoundException {
    JobConfigResolver jobConfigResolver = new PromJobConfigResolver();
    JobBuilder jobBuilder = new PromScrapeJobBuilder();
    ScrapeManager scrapeManager = new DefaultScrapeManager(MonitorComponent.METRIC, jobConfigResolver, jobBuilder);
    File file = ResourceUtils.getFile("clreplacedpath:static_targets_config.yml");
    scrapeManager.watchFreshScrapeConfigs(() -> {
        try {
            scrapeManager.updateScrapeConfigs(scrapeManager.loadConfigFileFromFilePath(file.getParent()));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        ScrapeJob job = ((DefaultScrapeManager) scrapeManager).getJobProcessor().getRunnings().get("prometheus");
        replacedert.replacedertTrue(job.isRunning());
    // replacedert.replacedertTrue(job.getState().isSuccessful());
    }, 0, 10, TimeUnit.SECONDS);
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

18 View Source File : DataSourceTests.java
License : Apache License 2.0
Project Creator : pivotal-cf

@Test
public void testDataSource() throws Exception {
    // To make CloudPlatform test preplaced
    try {
        System.setProperty("VCAP_APPLICATION", "yes");
        // To setup values used by CfEnv
        File file = ResourceUtils.getFile("clreplacedpath:vcap-services.json");
        String fileContents = new String(Files.readAllBytes(file.toPath()));
        mockVcapServices(fileContents);
        environmentPostProcessor.postProcessEnvironment(this.context.getEnvironment(), null);
        replacedertThat(this.context.getEnvironment().getProperty("spring.datasource.url")).isEqualTo(mysqlJdbcUrl);
        replacedertThat(this.context.getEnvironment().getProperty("spring.datasource.username")).isEqualTo("mysql_username");
        replacedertThat(this.context.getEnvironment().getProperty("spring.datasource.preplacedword")).isEqualTo("mysql_preplacedword");
    } finally {
        System.clearProperty("VCAP_APPLICATION");
    }
}

18 View Source File : FileServiceTest.java
License : MIT License
Project Creator : ls1intum

private void copyFile(String filePath, String destinationPath) {
    try {
        FileUtils.copyFile(ResourceUtils.getFile("clreplacedpath:test-data/repository-export/" + filePath), new File("./exportTest/" + destinationPath));
    } catch (IOException ex) {
        fail("Failed while copying test files", ex);
    }
}

18 View Source File : IpAddressService.java
License : MIT License
Project Creator : linj6

@PostConstruct
public void init() {
    try {
        String path = env.getProperty("geolite2.city.db.path");
        if (StringUtil.isNotBlank(path)) {
            addressDatabasePath = path;
        }
        // File database = new File(addressDatabasePath);
        File database = ResourceUtils.getFile("clreplacedpath:" + addressDatabasePath);
        reader = new DatabaseReader.Builder(database).build();
    } catch (Exception e) {
        logger.error("IP地址服务初始化异常:" + e.getMessage(), e);
    }
}

18 View Source File : AbstractFileResolvingResource.java
License : Apache License 2.0
Project Creator : langtianya

/**
 * This implementation returns a File reference for the underlying clreplaced path
 * resource, provided that it refers to a file in the file system.
 * @see org.springframework.util.ResourceUtils#getFile(java.net.URI, String)
 */
protected File getFile(URI uri) throws IOException {
    if (uri.getScheme().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
        return VfsResourceDelegate.getResource(uri).getFile();
    }
    return ResourceUtils.getFile(uri, getDescription());
}

18 View Source File : AddressBookServiceImplTest.java
License : Apache License 2.0
Project Creator : hashgraph

@BeforeAll
static void setupAll() throws IOException {
    Path addressBookPath = ResourceUtils.getFile("clreplacedpath:addressbook/testnet").toPath();
    initialAddressBookBytes = Files.readAllBytes(addressBookPath);
}

18 View Source File : QiniuCloudTest.java
License : GNU General Public License v3.0
Project Creator : getrebuild

@Test
public void testUploadAndMakeUrl() throws Exception {
    if (!QiniuCloud.instance().available())
        return;
    File file = ResourceUtils.getFile("clreplacedpath:clreplacedification-demo.xlsx");
    String uploadKey = QiniuCloud.instance().upload(file);
    System.out.println("uploadKey ... " + uploadKey);
    String downloadUrl = QiniuCloud.instance().url(uploadKey);
    System.out.println("downloadUrl ... " + downloadUrl);
    QiniuCloud.instance().delete(uploadKey);
}

18 View Source File : DemoInitializer.java
License : Apache License 2.0
Project Creator : epam

private Map<String, Map<Integer, File>> collectDemoData() throws Exception {
    Map<String, Map<Integer, File>> schemas = new HashMap<>();
    File dataDir = ResourceUtils.getFile(AVRO_SCHEMAS_DIR);
    dataDir.list((current, name) -> {
        File subjectDir = new File(current, name);
        if (!subjectDir.isDirectory()) {
            return false;
        }
        File[] schemaFiles = subjectDir.listFiles();
        if (schemaFiles == null) {
            throw new RuntimeException(String.format("Some problems occurs while processing '%s' dir.", subjectDir.getName()));
        }
        if (schemaFiles.length == 0) {
            return true;
        }
        Map<Integer, File> subjectSchemas = schemas.computeIfAbsent(subjectDir.getName(), k -> new TreeMap<>());
        for (File schema : schemaFiles) {
            subjectSchemas.put(parseVersion(schema), schema);
        }
        return true;
    });
    return schemas;
}

18 View Source File : FileCheckerTest.java
License : Apache License 2.0
Project Creator : EdgeGallery

@Test
void testValidFile() throws FileNotFoundException {
    File file = ResourceUtils.getFile("clreplacedpath:TestFile");
    replacedertDoesNotThrow(() -> FileChecker.check(file));
}

18 View Source File : FileCheckerTest.java
License : Apache License 2.0
Project Creator : EdgeGallery

@Test
void testValidFile() throws FileNotFoundException {
    File file = ResourceUtils.getFile("clreplacedpath:22406fba-fd5d-4f55-b3fa-89a45fee913a.csar");
    replacedertDoesNotThrow(() -> FileChecker.check(file));
}

18 View Source File : ApmServiceHelperTest.java
License : Apache License 2.0
Project Creator : EdgeGallery

@Test
void testGetMainServiceYaml() throws IOException {
    File file = ResourceUtils.getFile("clreplacedpath:sampleapp.csar");
    File packagesDir = ResourceUtils.getFile("clreplacedpath:packages");
    String indentedDir = packagesDir.getPath() + File.separator + PACKAGE_ID + TENANT_ID;
    String response = ApmServiceHelper.getMainServiceYaml(file.getPath(), indentedDir);
    replacedertNotNull(response);
}

18 View Source File : ApmServiceHelperTest.java
License : Apache License 2.0
Project Creator : EdgeGallery

@Test
void testSaveNullInputStreamToFile() throws IOException {
    File file = ResourceUtils.getFile("clreplacedpath:packages");
    String localFilePath = file.getPath();
    replacedertThrows(ApmException.clreplaced, () -> ApmServiceHelper.saveInputStreamToFile(null, PACKAGE_ID, TENANT_ID, localFilePath));
}

18 View Source File : ApmServiceHelperTest.java
License : Apache License 2.0
Project Creator : EdgeGallery

@Test
void testGetMainServiceYamlInvalid() throws IOException {
    File file = ResourceUtils.getFile("clreplacedpath:22406fba-fd5d-4f55-b3fa-89a45fee913b.csar");
    String localFilePath = file.getPath();
    File packagesDir = ResourceUtils.getFile("clreplacedpath:packages");
    String indentedDir = packagesDir.getPath() + File.separator + PACKAGE_ID + TENANT_ID;
    replacedertThrows(ApmException.clreplaced, () -> ApmServiceHelper.getMainServiceYaml(localFilePath, indentedDir));
}

18 View Source File : DkesService.java
License : Apache License 2.0
Project Creator : dkhadoop

public JSONObject getEsConf() throws IOException {
    File file2 = ResourceUtils.getFile("clreplacedpath:elasticsearch-zips-model2.json");
    String s = FileUtils.readFileToString(file2, "utf-8");
    JSONObject jsonObject = JSONObject.parseObject(s);
    return jsonObject;
}

18 View Source File : BindPropertiesToTargetTest.java
License : Apache License 2.0
Project Creator : binglind

@Test
public void bind() throws Exception {
    File file = ResourceUtils.getFile("clreplacedpath:yaml/bind.yaml");
    BindPoJo bindPoJo = BindPropertiesUtil.bindProperties(file, BindPoJo.clreplaced);
    replacedertThat(bindPoJo.getName()).isEqualTo("bindTest");
    replacedertThat(bindPoJo.getCamelCase()).isEqualTo("camelCase");
    replacedertThat(bindPoJo.getInvalidCamelCase()).isEqualTo("invalidCamelCase");
    replacedertThat(bindPoJo.getMap()).isNotNull();
    replacedertThat(bindPoJo.getMap().get("age")).isEqualTo(20);
    replacedertThat(bindPoJo.getMap().get("height")).isEqualTo(172);
    replacedertThat(bindPoJo.getMap().get("high-availability.cluster-id")).isEqualTo("daily");
    replacedertThat(bindPoJo.getList().get(0)).isEqualTo("one");
    replacedertThat(bindPoJo.getList().get(1)).isEqualTo("two");
    replacedertThat(bindPoJo.getArray()[0]).isEqualTo("one");
    replacedertThat(bindPoJo.getArray()[1]).isEqualTo("two");
    replacedertThat(bindPoJo.getCheckpointConfig().getCheckpointInterval()).isEqualTo(10000);
    replacedertThat(bindPoJo.getCheckpointConfig().getCheckpointTimeout()).isEqualTo(60000);
}

18 View Source File : SourceDescriptorTest.java
License : Apache License 2.0
Project Creator : binglind

@Test
public void buildMysqlSide() throws Exception {
    File file = ResourceUtils.getFile("clreplacedpath:yaml/mysql-side.yaml");
    SourceDescriptor sourceDescriptor = BindPropertiesUtil.bindProperties(file, SourceDescriptor.clreplaced);
    MysqlConnectorDescriptor connectorDescriptor = BindPropertiesUtil.bindProperties(sourceDescriptor.getConnector(), MysqlConnectorDescriptor.clreplaced);
    replacedertThat(connectorDescriptor.getUrl()).isNotNull();
    replacedertThat(connectorDescriptor.getUsername()).isNotNull();
    replacedertThat(connectorDescriptor.getPreplacedword()).isNotNull();
    Side side = sourceDescriptor.getSide();
    replacedertThat(side).isNotNull();
    replacedertThat(side.isAsync()).isTrue();
    SideTable sideTable = new SideTable();
    sideTable.setSide(side);
    MysqlAsyncSideFunction function = connectorDescriptor.buildSource(sourceDescriptor.getSchema(), null, sideTable);
    replacedertThat(function).isNotNull();
    Cache cache = function.create(side);
    replacedertThat(cache).isInstanceOf(LruCache.clreplaced);
}

18 View Source File : SinkDescriptorTest.java
License : Apache License 2.0
Project Creator : binglind

@Test
public void buildMysqlSink() throws Exception {
    File file = ResourceUtils.getFile("clreplacedpath:yaml/mysql-insert-sink.yaml");
    MysqlSinkDescriptor sinkDescriptor = BindPropertiesUtil.bindProperties(file, MysqlSinkDescriptor.clreplaced);
    replacedertThat(sinkDescriptor.getDriverName()).isNotNull();
    replacedertThat(sinkDescriptor.getUrl()).isNotNull();
    replacedertThat(sinkDescriptor.getUsername()).isEqualTo("root");
    replacedertThat(sinkDescriptor.getPreplacedword()).isEqualTo("123456");
    replacedertThat(sinkDescriptor.getParameterTypes().length).isEqualTo(4);
    JDBCAppendTableSink tableSink = sinkDescriptor.transform();
    replacedertThat(tableSink).isNotNull();
}

18 View Source File : SinkDescriptorTest.java
License : Apache License 2.0
Project Creator : binglind

@Test
public void buildTsdbSink() throws Exception {
    File file = ResourceUtils.getFile("clreplacedpath:yaml/tsdb-sink.yaml");
    TsdbSinkDescriptor sinkDescriptor = BindPropertiesUtil.bindProperties(file, TsdbSinkDescriptor.clreplaced);
    replacedertThat(sinkDescriptor.getMetricValues()).isNotNull();
    replacedertThat(sinkDescriptor.getTags()).isNotNull();
    replacedertThat(sinkDescriptor.getUrl()).isNotNull();
    TsdbTableSink tableSink = sinkDescriptor.transform();
    replacedertThat(tableSink).isNotNull();
}

18 View Source File : BaseConnectorTest.java
License : Apache License 2.0
Project Creator : binglind

@Before
public void before() throws Exception {
    UrlJarLoader jarLoader = new UrlJarLoader(null);
    File file = ResourceUtils.getFile("clreplacedpath:yaml/cluster.yaml");
    StandaloneClusterInfo clusterInfo = BindPropertiesUtil.bindProperties(file, StandaloneClusterInfo.clreplaced);
    client = ClusterClientFactory.createRestClient(clusterInfo, jarLoader);
}

18 View Source File : SentinelConverterTests.java
License : Apache License 2.0
Project Creator : alibaba

private String readFileContent(String file) {
    try {
        return FileUtils.readFileToString(ResourceUtils.getFile(StringUtils.trimAllWhitespace(file)));
    } catch (IOException e) {
        return "";
    }
}

18 View Source File : FileDataSourceProperties.java
License : Apache License 2.0
Project Creator : alibaba

@Override
public void preCheck(String dataSourceName) {
    super.preCheck(dataSourceName);
    try {
        this.setFile(ResourceUtils.getFile(StringUtils.trimAllWhitespace(this.getFile())).getAbsolutePath());
    } catch (IOException e) {
        throw new RuntimeException("[Sentinel Starter] DataSource " + dataSourceName + " handle file [" + this.getFile() + "] error: " + e.getMessage(), e);
    }
}

18 View Source File : BulkImportTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco

/**
 * MNT-15367: Unable to bulk import filenames with Portuguese characters in a Linux environment
 *
 * @throws Throwable
 */
@Test
public void testImportFilesWithSpecialCharacters() throws Throwable {
    NodeRef folderNode = topLevelFolder.getNodeRef();
    NodeImporter nodeImporter = null;
    File source = ResourceUtils.getFile("clreplacedpath:bulkimport4");
    // Simulate the name of the file with an invalid encoding.
    String fileName = new String("135 CarbonÔÇô13 NMR spectroscopy_DS_NS_final_cau.txt".getBytes(Charset.forName("ISO-8859-1")), Charset.forName("UTF-8"));
    Path dest = source.toPath().resolve("encoding");
    try {
        dest = Files.createDirectory(dest);
    } catch (FileAlreadyExistsException ex) {
    // It is fine if the folder already exists, though it should not.
    }
    Path destFile = dest.resolve(fileName);
    unpack(source.toPath(), destFile);
    txn = transactionService.getUserTransaction();
    txn.begin();
    nodeImporter = streamingNodeImporterFactory.getNodeImporter(ResourceUtils.getFile("clreplacedpath:bulkimport4/encoding"));
    BulkImportParameters bulkImportParameters = new BulkImportParameters();
    bulkImportParameters.setTarget(folderNode);
    bulkImportParameters.setReplaceExisting(true);
    bulkImportParameters.setDisableRulesService(true);
    bulkImportParameters.setBatchSize(40);
    bulkImporter.bulkImport(bulkImportParameters, nodeImporter);
    replacedertEquals(1, bulkImporter.getStatus().getNumberOfContentNodesCreated());
    checkFiles(folderNode, null, 0, 1, new ExpectedFile[] { new ExpectedFile(fileName, MimetypeMap.MIMETYPE_TEXT_PLAIN) }, null);
    Files.deleteIfExists(destFile);
    Files.deleteIfExists(dest);
}

18 View Source File : AbstractBaseApiTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco

protected File getResourceFile(String fileName) throws FileNotFoundException {
    URL url = NodeApiTest.clreplaced.getClreplacedLoader().getResource(RESOURCE_PREFIX + fileName);
    if (url == null) {
        fail("Cannot get the resource: " + fileName);
    }
    return ResourceUtils.getFile(url);
}

18 View Source File : UploadWebScriptTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco

private File getResourceFile(String fileName) throws FileNotFoundException {
    URL url = VersionableAspectTest.clreplaced.getClreplacedLoader().getResource(RESOURCE_PREFIX + fileName);
    if (url == null) {
        fail("Cannot get the resource: " + fileName);
    }
    return ResourceUtils.getFile(url);
}

18 View Source File : CustomModelImportTest.java
License : GNU Lesser General Public License v3.0
Project Creator : Alfresco

private File getResourceFile(String xmlFileName) throws FileNotFoundException {
    URL url = CustomModelImportTest.clreplaced.getClreplacedLoader().getResource(RESOURCE_PREFIX + xmlFileName);
    if (url == null) {
        fail("Cannot get the resource: " + xmlFileName);
    }
    return ResourceUtils.getFile(url);
}

17 View Source File : RestartServer.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void updateTimeStamp(URL url) {
    try {
        URL actualUrl = ResourceUtils.extractJarFileURL(url);
        File file = ResourceUtils.getFile(actualUrl, "Jar URL");
        file.setLastModified(System.currentTimeMillis());
    } catch (Exception ex) {
    // Ignore
    }
}

17 View Source File : ClassPathFolders.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void addUrl(URL url) {
    if (url.getProtocol().equals("file") && url.getPath().endsWith("/")) {
        try {
            this.folders.add(ResourceUtils.getFile(url));
        } catch (Exception ex) {
            logger.warn("Unable to get clreplacedpath URL " + url);
            logger.trace("Unable to get clreplacedpath URL " + url, ex);
        }
    }
}

17 View Source File : AdminController.java
License : GNU General Public License v3.0
Project Creator : luoye663

@RequestMapping("setAnnouncement")
public String setAnnouncement(String text) throws IOException {
    File file = ResourceUtils.getFile("clreplacedpath:announcement.txt");
    FileWriter writer = new FileWriter(file);
    writer.write(text);
    writer.close();
    return "ok";
}

17 View Source File : AbstractDownloaderTest.java
License : Apache License 2.0
Project Creator : hashgraph

protected static AddressBook loadAddressBook(String filename) throws IOException {
    Path addressBookPath = ResourceUtils.getFile(String.format("clreplacedpath:addressbook/%s", filename)).toPath();
    byte[] addressBookBytes = Files.readAllBytes(addressBookPath);
    EnreplacedyId enreplacedyId = EnreplacedyId.of(0, 0, 102, EnreplacedyTypeEnum.FILE);
    long now = Instant.now().getEpochSecond();
    return addressBookFromBytes(addressBookBytes, now, enreplacedyId);
}

17 View Source File : DatabaseBackupTest.java
License : GNU General Public License v3.0
Project Creator : getrebuild

@Test
public void zip() throws Exception {
    File file = ResourceUtils.getFile("clreplacedpath:metadata-conf.xml");
    File dest = RebuildConfiguration.getFileOfTemp(file.getName() + ".zip");
    DatabaseBackup.zip(file, dest);
    System.out.println("Zip to : " + dest);
}

17 View Source File : TemplateExtractorTest.java
License : GNU General Public License v3.0
Project Creator : getrebuild

@Test
public void testExtractVars() throws FileNotFoundException {
    File template = ResourceUtils.getFile("clreplacedpath:report-template-v2.xlsx");
    Set<String> vars = new TemplateExtractor(template, true).extractVars();
    System.out.println(vars);
    replacedertions.replacedertTrue(vars.size() >= 7);
}

17 View Source File : DataReportGeneratorTest.java
License : GNU General Public License v3.0
Project Creator : getrebuild

@Test
public void testGeneratorV2Simple() throws FileNotFoundException {
    File template = ResourceUtils.getFile("clreplacedpath:report-template-v2.xlsx");
    ID record = addRecordOfTestAllFields(SIMPLE_USER);
    File file = ((EasyExcelGenerator) new EasyExcelGenerator(template, record).setUser(UserService.ADMIN_USER)).generate();
    System.out.println("Report : " + file);
}

17 View Source File : FlowParserTest.java
License : GNU General Public License v3.0
Project Creator : getrebuild

/**
 * @param fileNo
 * @return
 * @throws IOException
 */
static FlowParser createFlowParser(int fileNo) throws IOException {
    File file = ResourceUtils.getFile("clreplacedpath:approval-flow" + fileNo + ".json");
    try (InputStream in = new FileInputStream(file)) {
        JSONObject flowDefinition = JSON.parseObject(in, null);
        return new FlowParser(flowDefinition);
    }
}

17 View Source File : XlsMonitoringStatsWriter.java
License : Apache License 2.0
Project Creator : epam

private Workbook getTemplateWorkbook() throws IOException, InvalidFormatException {
    if (templatePath.startsWith(ResourceUtils.CLreplacedPATH_URL_PREFIX)) {
        try (InputStream clreplacedPathResource = getClreplaced().getResourcereplacedtream(templatePath.substring(ResourceUtils.CLreplacedPATH_URL_PREFIX.length()))) {
            return WorkbookFactory.create(clreplacedPathResource);
        }
    } else {
        return WorkbookFactory.create(ResourceUtils.getFile(templatePath), null, true);
    }
}

See More Examples