Java Code Examples for org.aspectj.util.FileUtil

The following examples show how to use org.aspectj.util.FileUtil. These examples are extracted from open source projects. 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 Project: java-trader   Source File: TechnicalAnalysisServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
public static void loadRepositorySql(Connection conn) throws Exception
{
    byte[] data = FileUtil.readAsByteArray(TechnicalAnalysisServiceImpl.class.getClassLoader().getResourceAsStream("/repository.sql"));
    String text = new String(data, StringUtil.UTF8);

    try(Statement stmt=conn.createStatement();){
        StringBuilder sql = new StringBuilder();
        for(String line:StringUtil.text2lines(text, true, true)) {
            if ( line.startsWith("--")) {
                continue;
            }
            if ( sql.length()>0 ) {
                sql.append("\n");
            }
            sql.append(line);
            if ( line.endsWith(";")) {
                stmt.execute(sql.toString());
                sql.setLength(0);;
            }
        }
    }
}
 
Example 2
Source Project: halyard   Source File: LocalFileConverter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String convert(String value) {
  if (EncryptedSecret.isEncryptedSecret(value) || isConfigServerResource(value)) {
    return value;
  }

  if (GlobalApplicationOptions.getInstance().isUseRemoteDaemon()) {
    try {
      return FileUtil.readAsString(new File(value));
    } catch (IOException e) {
      throw new HalException(
          Problem.Severity.FATAL,
          "Was passed parameter " + value + " to unreadable file: " + e.getMessage());
    }
  }
  return new File(value).getAbsolutePath();
}
 
Example 3
@Test
public void testNotAuthorized() throws Exception {
  myArtifactsCollections.add(DeployTestUtils.buildArtifactsCollection(createTempFilesFactory(), "dest1", "dest2"));
  final BuildProcess process = new FtpBuildProcessAdapter(myContext, "127.0.0.1:" + testPort, myUsername, "wrongpassword", myArtifactsCollections);

  process.start();
  new WaitFor(5000) {
    @Override
    protected boolean condition() {
      return process.isFinished();
    }
  };
  assertTrue("Failed to finish test in time", process.isFinished());
  assertEquals(process.waitFor(), BuildFinishedStatus.FINISHED_FAILED);
  assertEquals(FileUtil.listFiles(myRemoteDir).length, 0);
}
 
Example 4
Source Project: gocd   Source File: MaterialDatabaseGitUpdaterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRemoveFlyweightWhenConfiguredBranchDoesNotExist() throws Exception {
    File flyweightDir = new File("pipelines", "flyweight");
    FileUtils.deleteQuietly(flyweightDir);

    material = new GitMaterial(testRepo.projectRepositoryUrl(), "bad-bad-branch");

    try {
        updater.updateMaterial(material);
        fail("material update should have failed as given branch does not exist in repository");
    } catch (Exception e) {
        //ignore
    }

    MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);

    assertThat(materialInstance, is(nullValue()));
    assertThat(FileUtil.listFiles(flyweightDir).length, is(0));//no flyweight dir left behind
}
 
Example 5
public String getConfigurationContent(String host, String confFileName)
		throws Exception {
	String fileContent = null;
	Map<String, Object> configValues = getConfigValueMap();

	String udpRecvChannel = "udp_recv_channel {\n port = "
			+ configValues.get("port") + " \n } ";
	// 'udp_recv_channel' value for gmond.conf
	configValues.put("udp_recv_channel", "/*" + udpRecvChannel + "*/");

	if (((String) advanceConf
			.get(GangliaConstants.ClusterProperties.GMETAD_HOST))
			.equals(host)) {
		StringBuffer nodeIpPorts = new StringBuffer();
		// Preparing a String of nodeIp:port of gmetad node used in
		// data_source in gmetad.conf.
		nodeIpPorts
				.append(advanceConf
						.get(GangliaConstants.ClusterProperties.GMETAD_HOST))
				.append(Symbols.STR_COLON);
		nodeIpPorts.append(advanceConf
				.get(GangliaConstants.ClusterProperties.GANGLIA_PORT));
		// Putting the nodeIpsPorts string in map
		configValues.put("nodeIpsPorts", nodeIpPorts.toString());
		// On gmond nodes other than Gmetad node commenting
		// udp_recv_channel block
		configValues.put("udp_recv_channel", udpRecvChannel);
	}
	// Reading the content of the template file
	fileContent = FileUtil.readAsString(new File(confFileName));

	// Creating a string substitutor using config values map
	StrSubstitutor sub = new StrSubstitutor(configValues);

	// Replacing the config values key found in the file content with
	// respected values.
	return sub.replace(fileContent);
}
 
Example 6
public String getGmetadConfigurationContent(String host) throws Exception {
	String fileContent = null;
	String confFileName = (String) advanceConf
			.get(GangliaConstants.ClusterProperties.SERVER_CONF_FOLDER)
			+ GangliaConstants.ConfigurationFiles.GMOND_CONF;

	Map<String, Object> configValues = getConfigValueMap();

	String udpRecvChannel = "udp_recv_channel {\n port = "
			+ configValues.get("port") + " \n } ";
	configValues.put("udp_recv_channel", "/*" + udpRecvChannel + "*/");

	if (((String) advanceConf
			.get(GangliaConstants.ClusterProperties.GMETAD_HOST))
			.equals(host)) {
		confFileName = (String) advanceConf
				.get(GangliaConstants.ClusterProperties.SERVER_CONF_FOLDER)
				+ GangliaConstants.ConfigurationFiles.GMETAD_CONF;
		StringBuffer nodeIpPorts = new StringBuffer();
		// Preparing a String of nodeIp:port of gmetad node.
		nodeIpPorts
				.append(advanceConf
						.get(GangliaConstants.ClusterProperties.GMETAD_HOST))
				.append(Symbols.STR_COLON);
		nodeIpPorts.append(advanceConf
				.get(GangliaConstants.ClusterProperties.GANGLIA_PORT));
		// Putting the nodeIpsPorts string in map
		configValues.put("nodeIpsPorts", nodeIpPorts.toString());
		// On gmond nodes other than Gmetad node commenting
		// udp_recv_channel block
		configValues.put("udp_recv_channel", udpRecvChannel);
	}
	// Reading the content of the template file
	fileContent = FileUtil.readAsString(new File(confFileName));

	// Creating a string substitutor using config values map
	StrSubstitutor sub = new StrSubstitutor(configValues);

	// Replacing the config values key found in the file content with
	// respected values.
	return sub.replace(fileContent);
}