Java Code Examples for java.io.File#separator()

The following examples show how to use java.io.File#separator() . 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: BasicTests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Runs the actual tests in nested class TestMain.
 * The reason for running the tests in a separate process
 * is that we need to modify the class path.
 */
private static void runTests(int pid) throws Throwable {
    final String sep = File.separator;

    // Need to add jdk/lib/tools.jar to classpath.
    String classpath =
        System.getProperty("test.class.path", "") + File.pathSeparator +
        System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
    String testClassDir = System.getProperty("test.classes", "") + sep;

    // Argumenta : -classpath cp BasicTests$TestMain pid agent badagent redefineagent
    String[] args = {
        "-classpath",
        classpath,
        "BasicTests$TestMain",
        Integer.toString(pid),
        testClassDir + "Agent.jar",
        testClassDir + "BadAgent.jar",
        testClassDir + "RedefineAgent.jar" };
    OutputAnalyzer output = ProcessTools.executeTestJvm(args);
    output.shouldHaveExitValue(0);
}
 
Example 2
Source File: Cursor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static String initCursorDir() {
    String jhome = java.security.AccessController.doPrivileged(
           new sun.security.action.GetPropertyAction("java.home"));
    return jhome +
        File.separator + "lib" + File.separator + "images" +
        File.separator + "cursors" + File.separator;
}
 
Example 3
Source File: UUIDConversion.java    From PlayerVaults with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    Logger logger = PlayerVaults.getInstance().getLogger();

    File newDir = PlayerVaults.getInstance().getVaultData();
    if (newDir.exists()) {
        return;
    }

    File oldVaults = new File(PlayerVaults.getInstance().getDataFolder() + File.separator + "vaults");
    if (oldVaults.exists()) {
        logger.info("********** Starting conversion to UUIDs for PlayerVaults **********");
        logger.info("This might take awhile.");
        logger.info(oldVaults.toString() + " will remain as a backup.");

        for (File file : oldVaults.listFiles()) {
            if (file.isDirectory()) {
                continue; // backups folder.
            }
            OfflinePlayer player = Bukkit.getOfflinePlayer(file.getName().replace(".yml", ""));
            if (player == null) {
                logger.warning("Unable to convert file because player never joined the server: " + file.getName());
                break;
            }

            File newFile = new File(PlayerVaults.getInstance().getVaultData(), player.getUniqueId().toString() + ".yml");
            file.mkdirs();
            try {
                Files.copy(file, newFile);
                logger.info("Successfully converted vault file for " + player.getName());
            } catch (IOException e) {
                logger.severe("Couldn't convert vault file for " + player.getName());
            }
        }

        logger.info("********** Conversion done ;D **********");
    }
}
 
Example 4
Source File: JTMTestCase.java    From ontopia with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes the jtm file, serializes the resulting topic map into a jtm file in the directory 'jtm-in', reads this
 * file in again and canonicalizes the result into the directory 'jtm-out'. Compares the file in 'jtm-out' with a
 * baseline file in 'baseline'.
 */
@Test
public void testWriter() throws IOException {
  TestFileUtils.verifyDirectory(base, "jtm-in");
  TestFileUtils.verifyDirectory(base, "jtm-out");

  // Path to the input topic map document.
  String in = TestFileUtils.getTestInputFile(testdataDirectory, "in", filename);
  // Path to the baseline (canonicalized output of the source topic map).
  String baseline = TestFileUtils.getTestInputFile(testdataDirectory, "baseline",
          filename + ".cxtm");

  // Path to the intermediate jtm file
  String jtm = base + File.separator + "jtm-in" + File.separator + filename;

  // Path to the output (canonicalized output of exported jtm topic map).
  File out = new File(base + File.separator + "jtm-out" + File.separator + filename
          + ".cxtm");

  TopicMapIF tm = new JTMTopicMapReader(TestFileUtils.getTestInputURL(in)).read();

  // serialize the imported topic map into jtm again
  FileOutputStream fos = new FileOutputStream(jtm);
  (new JTMTopicMapWriter(fos)).write(tm);

  // read in the intermediate jtm file
  tm = new JTMTopicMapReader(new File(jtm)).read();

  // Canonicalize the imported jtm.
  new CanonicalXTMWriter(out).write(tm);

  // compare results
  Assert.assertTrue("canonicalizing the test file " + filename
          + " gives a different result than canonicalizing the jtm export of "
          + filename + ".", TestFileUtils.compareFileToResource(out, baseline));
}
 
Example 5
Source File: UsagePublisherUtils.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public static String getUploadedFileDirPath(String tenantDomain, String tempDirName) {
    //Temporary directory is used for keeping the uploaded files
    // i.e [APIUsageFileLocation]/api-usage-data/tenantDomain/tvtzC
    String storageLocation = System.getProperty("APIUsageFileLocation");
    return ((storageLocation != null && !storageLocation.isEmpty())
            ? storageLocation : CarbonUtils.getCarbonHome())
            + File.separator + MicroGatewayAPIUsageConstants.API_USAGE_OUTPUT_DIRECTORY + File.separator
            + tenantDomain + File.separator + tempDirName;
}
 
Example 6
Source File: AudioFile.java    From AudioAnchor with GNU General Public License v3.0 5 votes vote down vote up
AudioFile(int id, String title, int albumId, int time, int completedTime, String albumTitle, String coverPath, String baseDirectory) {
    mId = id;
    mTitle = title;
    mAlbumId = albumId;
    mTime = time;
    mCompletedTime = completedTime;
    mAlbumTitle = albumTitle;
    if (coverPath != null) {
        mCoverPath = baseDirectory + File.separator + coverPath;
    } else {
        mCoverPath = null;
    }
    mPath = baseDirectory + File.separator + mAlbumTitle + File.separator + mTitle;
}
 
Example 7
Source File: JarslinkActivatorTest.java    From sofa-jarslink with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    PluginContext pluginContext = Mockito.mock(PluginContext.class);
    PluginActivator pluginActivator = new JarslinkActivator();
    pluginActivator.start(pluginContext);

    String tempPath = FileUtils.getTempDirectoryPath() + File.separator
                      + Constants.JARSLINK_IDENTITY;
    Assert.assertTrue(tempPath.equals(EnvironmentUtils
        .getProperty(Constants.JARSLINK_WORKING_DIR)));
}
 
Example 8
Source File: CrashHandler.java    From AndroidMVVMSample with Apache License 2.0 5 votes vote down vote up
private static String getPath(File f, String subDir) {
    File file = new File(f.getAbsolutePath() + File.separator + subDir);
    if (!file.exists()) {
        file.mkdirs();
    }
    return file.getAbsolutePath();
}
 
Example 9
Source File: WebAppResourceLoader.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 
 * @param root 
 */
public WebAppResourceLoader(String root)
{

	if (root != null)
		this.root = root;
	else
	{
		this.root = BeetlUtil.getWebRoot() + File.separator;
	}

}
 
Example 10
Source File: CLI.java    From cloudExplorer with GNU General Public License v3.0 5 votes vote down vote up
void syncFromS3(String folder) {
    try {
        if (folder != null) {
            System.out.print("\n\nStarting sync from Folder: " + folder + " on bucket: " + bucket + " to destination: " + destination + ".\n");
        } else {
            System.out.print("\n\nStarting sync from bucket: " + bucket + " to destination: " + destination + ".\n");
        }
        reloadObjects();
        File[] foo = new File[object_array.length];
        for (int i = 1; i != object_array.length; i++) {
            if (object_array[i] != null) {
                int found = 0;
                foo[i] = new File(destination + File.separator + object_array[i]);
                if (folder != null) {
                    if (object_array[i].contains(folder)) {
                        syncengine = new SyncEngine(object_array[i], null, null, object_array[i], bucket, access_key, secret_key, endpoint, null, null, null, false, destination);
                    }
                } else {
                    syncengine = new SyncEngine(object_array[i], null, null, object_array[i], bucket, access_key, secret_key, endpoint, null, null, null, false, destination);

                }
                executor.execute(syncengine);
                System.gc();
            }
        }
        executor.shutdown();
        while (!executor.isTerminated()) {
        }
        System.out.print("\nSync operation finished running");
    } catch (Exception sync) {
    }

}
 
Example 11
Source File: WsImportTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String getWsImport() {
    String javaHome = System.getProperty("java.home");
    if (javaHome.endsWith("jre")) {
        javaHome = new File(javaHome).getParent();
    }
    String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";
    if (System.getProperty("os.name").startsWith("Windows")) {
        wsimport = wsimport.concat(".exe");
    }
    return wsimport;
}
 
Example 12
Source File: GraphDatabaseConfiguration.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
private static String getFileName(String dir, String file) {
    if (!dir.endsWith(File.separator)) dir = dir + File.separator;
    return dir + file;
}
 
Example 13
Source File: EndpointsToolAction.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
protected String getWarOutputPath(Option outputOption, String warPath) {
  if (outputOption.getValue() != null) {
    return outputOption.getValue();
  }
  return warPath + File.separator + DEFAULT_WAR_OUTPUT_PATH_SUFFIX;
}
 
Example 14
Source File: IgniteWalConverterSensitiveDataTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
    super.beforeTestsStarted();

    sysOut = System.out;
    testOut = new ByteArrayOutputStream(16 * 1024);

    int nodeId = 0;

    IgniteEx crd = startGrid(nodeId);
    crd.cluster().active(true);

    try (Transaction tx = crd.transactions().txStart()) {
        IgniteCache<Object, Object> cache = crd.cache(DEFAULT_CACHE_NAME);

        sensitiveValues.add(SENSITIVE_DATA_VALUE_PREFIX + 0);
        sensitiveValues.add(SENSITIVE_DATA_VALUE_PREFIX + 1);
        sensitiveValues.add(SENSITIVE_DATA_VALUE_PREFIX + 2);

        String val0 = sensitiveValues.get(0);
        String val1 = sensitiveValues.get(1);
        String val2 = sensitiveValues.get(2);

        cache.put(val0, val0);
        cache.withKeepBinary().put(val1, val1);
        cache.put(val2, new Person(1, val2));

        tx.commit();
    }

    GridKernalContext kernalCtx = crd.context();
    IgniteWriteAheadLogManager wal = kernalCtx.cache().context().wal();

    for (WALRecord walRecord : withSensitiveData()) {
        if (isIncludeIntoLog(walRecord))
            wal.log(walRecord);
    }

    sensitiveValues.add(SENSITIVE_DATA_VALUE_PREFIX);

    wal.flush(null, true);

    IgniteConfiguration cfg = crd.configuration();

    String wd = cfg.getWorkDirectory();
    String wp = cfg.getDataStorageConfiguration().getWalPath();
    String fn = kernalCtx.pdsFolderResolver().resolveFolders().folderName();

    walDirPath = wd + File.separator + wp + File.separator + fn;
    pageSize = cfg.getDataStorageConfiguration().getPageSize();

    stopGrid(nodeId);
}
 
Example 15
Source File: SelectTemplateWizardPanel.java    From nextreports-designer with Apache License 2.0 4 votes vote down vote up
private File getSelectedTemplateFile() {
    String template = (String)defTemplateList.getSelectedValue() + TemplateFileFilter.TEMPLATE_FILE_EXT;
    return new File(Globals.USER_DATA_DIR + "/templates" + File.separator + template);
}
 
Example 16
Source File: JavaLauncher.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Find a suitable JVM on the user's system.
 * 
 * @return - path to java binary
 */
public static String findJVM() {

	String jvm = null;
	jvm = System.getProperty("java.home");

	// handle property not set
	if (jvm == null) {

		log.warn("Java home property not set, just guessing with a general java call, and will probably fail.");

		// just take a guess an hope it's in the classpath
		jvm = "java";

	}

	// add binary folder
	jvm = jvm + File.separator + "bin" + File.separator + "java";

	return jvm;
}
 
Example 17
Source File: PictureExternalPreviewActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
public String showLoadingImage(String urlPath) {
    Uri outImageUri = null;
    OutputStream outputStream = null;
    InputStream inputStream = null;
    BufferedSource inBuffer = null;
    try {
        if (SdkVersionUtils.checkedAndroid_Q()) {
            outImageUri = createOutImageUri();
        } else {
            String suffix = PictureMimeType.getLastImgSuffix(mMimeType);
            String state = Environment.getExternalStorageState();
            File rootDir =
                    state.equals(Environment.MEDIA_MOUNTED)
                            ? Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
                            : getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
            if (rootDir != null) {
                if (!rootDir.exists()) {
                    rootDir.mkdirs();
                }
                File folderDir = new File(!state.equals(Environment.MEDIA_MOUNTED)
                        ? rootDir.getAbsolutePath() : rootDir.getAbsolutePath() + File.separator + PictureMimeType.CAMERA + File.separator);
                if (!folderDir.exists() && folderDir.mkdirs()) {
                }
                String fileName = DateUtils.getCreateFileName("IMG_") + suffix;
                File file = new File(folderDir, fileName);
                outImageUri = Uri.fromFile(file);
            }
        }
        if (outImageUri != null) {
            outputStream = Objects.requireNonNull(getContentResolver().openOutputStream(outImageUri));
            URL u = new URL(urlPath);
            inputStream = u.openStream();
            inBuffer = Okio.buffer(Okio.source(inputStream));
            boolean bufferCopy = PictureFileUtils.bufferCopy(inBuffer, outputStream);
            if (bufferCopy) {
                return PictureFileUtils.getPath(this, outImageUri);
            }
        }
    } catch (Exception e) {
        if (outImageUri != null && SdkVersionUtils.checkedAndroid_Q()) {
            getContentResolver().delete(outImageUri, null, null);
        }
    } finally {
        PictureFileUtils.close(inputStream);
        PictureFileUtils.close(outputStream);
        PictureFileUtils.close(inBuffer);
    }
    return null;
}
 
Example 18
Source File: GemFireXDDataExtractorDUnit.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
public void testMultiDiskStore() throws Exception {
  String tableName = "REPLICATE_TABLE";
  String secondTableName = "REPLICATE_2_TABLE";
  String server1Name = "server1";
  String server2Name = "server2";
  int numDDL = 4;
  startVMs(1, 2);
  clientCreateDiskStore(1, testDiskStoreName);
  clientCreateDiskStore(1, secondDiskStoreName);
 
  clientCreatePersistentReplicateTable(1, tableName, testDiskStoreName);
  clientCreatePersistentReplicateTable(1, secondTableName, secondDiskStoreName);
  //create table
  //insert/update/delete data
  insertData(tableName, 0, 1000);
  updateData(tableName, 300, 600);
  deleteData(tableName, 600, 900);
  
  insertData(secondTableName, 0, 1000);
  updateData(secondTableName, 300, 600);
  deleteData(secondTableName, 600, 900);

  String server1Directory = getVM(-1).getSystem().getSystemDirectory() + "_" + getVM(-1).getPid();
  String server2Directory = getVM(-2).getSystem().getSystemDirectory() + "_" + getVM(-2).getPid();
  
  this.serverExecute(1, this.getCopyDataDictionary(server1Directory));
  this.serverExecute(2,  this.getCopyDataDictionary(server2Directory));
  
  this.serverExecute(1,  this.getCopyOplogsRunnable(server1Directory, testDiskStoreName));
  this.serverExecute(2,  this.getCopyOplogsRunnable(server2Directory, testDiskStoreName));
  this.serverExecute(1,  this.getCopyOplogsRunnable(server1Directory, secondDiskStoreName));
  this.serverExecute(2,  this.getCopyOplogsRunnable(server2Directory, secondDiskStoreName));

  String propertiesFileName = "test_salvage.properties";
  Properties properties = new Properties();
  String server1CopyDir = server1Directory + File.separator + copyDirectory;
  String server2CopyDir = server2Directory + File.separator + copyDirectory;
  properties.setProperty(server1Name, server1CopyDir + "," + server1CopyDir + File.separator + testDiskStoreName + "," + server1CopyDir + File.separator + secondDiskStoreName);
  properties.setProperty(server2Name, server2CopyDir + "," + server2CopyDir + File.separator + testDiskStoreName + "," + server2CopyDir + File.separator + secondDiskStoreName);
  properties.store(new FileOutputStream(new File(propertiesFileName)), "test properties");
  
  String userName =  TestUtil.currentUserName == null? "APP":TestUtil.currentUserName;
  //pass in properties file to salvager
  String args[] = new String[] {"property-file=" + propertiesFileName, "--user-name=" + userName};
  disconnectTestInstanceAndCleanUp();
  
  GemFireXDDataExtractorImpl salvager = GemFireXDDataExtractorImpl.doMain(args);

  String outputDirectoryString = salvager.getOutputDirectory();
  File outputDirectory = new File(outputDirectoryString);
  assertTrue(outputDirectory.exists());
  
  File server1OutputDirectory = new File(outputDirectory, server1Name);
  assertTrue(serverExportedCorrectly(server1OutputDirectory, new String[] {tableName, secondTableName}, numDDL));
  
  File server2OutputDirectory = new File(outputDirectory, server2Name);
  assertTrue(serverExportedCorrectly(server2OutputDirectory, new String[] {tableName, secondTableName}, numDDL));

  File summaryFile = new File(outputDirectory, "Summary.txt");
  assertTrue(summaryFile.exists());
  
  File recommended = new File(outputDirectory, "Recommended.txt");
  assertTrue(recommended.exists());  
  FileUtils.deleteDirectory(outputDirectory);
}
 
Example 19
Source File: SVMLocator.java    From wasindoor with Apache License 2.0 4 votes vote down vote up
public boolean locate_file(String gmLocatorFileAddr, Integer buildingId,
		Integer floor, Integer rowsInOneline, Integer numOfFolds,
		String filename) {
	String completeFileAddr = gmLocatorFileAddr + File.separator + buildingId + File.separator
			+ floor + File.separator + filename;

	int end_index = completeFileAddr.lastIndexOf(".");
	String fileAddrTrim = completeFileAddr.substring(0, end_index);

	File inputfile = new File(completeFileAddr);
	if (!inputfile.exists()) {
		System.out
				.println("File Do Not Exist! �ļ������ڣ�������������������ļ�·�������ļ����Ƿ���ȷ.");
		return false;
	}

	int line = 0;

	try {
		System.out.println("����Ϊ��λ��ȡ�ļ����ݣ�һ�ζ�һ���У�");
		BufferedReader reader = new BufferedReader(
				new FileReader(inputfile));
		FileWriter writer = new FileWriter(fileAddrTrim + "Result");

		String[] strs = null;
		String lineString = null;

		// һ�ζ���һ�У�ֱ������nullΪ�ļ�����
		while ((lineString = reader.readLine()) != null) {

			if (lineString.trim().length() == 0) {
				continue;
			}

			strs = lineString.split("\\s+"); // һ�����������ո�ָ�

			if (strs.length != rowsInOneline) {
				System.out.println("�趨λ���ļ�" + completeFileAddr
						+ " ��: line " + (line + 1)
						+ " has a wrong format!!!");
				return false;
			}

			double zAngle = Double.parseDouble(strs[0]);
			double xMag = Double.parseDouble(strs[1]);
			double yMag = Double.parseDouble(strs[2]);
			double zMag = Double.parseDouble(strs[3]);

			GeomagneticEntity entity = new GeomagneticEntity();
			entity.setBuildingId(buildingId);
			entity.setFloor(floor);
			entity.setzAngle(zAngle);
			entity.setxMagnetic(xMag);
			entity.setyMagnetic(yMag);
			entity.setzMagnetic(zMag);

			Integer location = locate(entity, gmLocatorFileAddr, numOfFolds);
			writer.write(location + "\r\n");

			line++;
		}

		reader.close();
		writer.flush();
		writer.close();

	} catch (IOException ex) {
		ex.printStackTrace();
		return false;
	}

	System.out.println("����ɶ�λ������λ" + line + "�С�");

	return true;
}
 
Example 20
Source File: ClientIntegrationE2ETest.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * This test integrates 2 branches that have completely different files. In the source
 * dir, files are in various states of submission (open for edit, added, submitted,
 * deleted/not submitted, deleted). Verifies files are properly added to the new directory
 * on final submit after resolve.
 */
@Test
public void testIntegrateBranchesAllDiffFiles() throws Exception {

    IChangelist changelist = null;

    int expNumIntegrated = 8;
    int expNumResolved = 1;
    int expNumSubmitted = 8;

    debugPrintTestName("testIntegrateBranchesAllDiffFiles");

    String clientRoot = client.getRoot();
    assertNotNull("clientRoot should not be Null.", clientRoot);

    //create changelist
    changelist = createTestChangelist(server, client,
            "Changelist to submit edited files " + getName());
    int changelistId = changelist.getId();

    //build to and from filepaths
    String basePath = clientRoot + File.separator + mainBranchPath;
    String baseFileString = basePath + File.separator + "HGTV" + File.separator + "..."; //use this in prepareTestDir
    String fromFileString = basePath + File.separator + "TLCP" + File.separator + "...";
    String toFileStringBase = basePath + File.separator + mainToDir + changelistId + File.separator;
    String toFileString = toFileStringBase + "...";

    String[] expFinalFileList = new String[]{
            toFileStringBase + "admin" + File.separator + "displayTool.pl", //TLCP & HGTV
            toFileStringBase + "src" + File.separator + "hbop1.html",  //TLCP
            toFileStringBase + "src" + File.separator + "hbop4.java",
            toFileStringBase + "src" + File.separator + "hbop5.txt",
            toFileStringBase + "src" + File.separator + "hbop6.txt",
            toFileStringBase + "src" + File.separator + "hbop7.txt",
            toFileStringBase + "src" + File.separator + "p4merge_help.png",
            toFileStringBase + "src" + File.separator + "bindetmi2.dll",
            toFileStringBase + "src" + File.separator + "homePlan.txt",  //HGTV
            toFileStringBase + "src" + File.separator + "homeWorks.html",
            toFileStringBase + "src" + File.separator + "hProj.java",
            toFileStringBase + "src" + File.separator + "lProj.java",
            toFileStringBase + "src" + File.separator + "proj1.dll"
    };

    //build file dirs
    String[] fNameList = prepareTestDir(baseFileString, toFileString);

    //integrate and verify
    boolean baselessMergeVal = true;
    List<IFileSpec> integratedFiles = taskAddIntegrateTestFiles(server, fromFileString, toFileString, changelistId,
            baselessMergeVal, fNameList);
    assertEquals("Number of files not integrated as expected.", expNumIntegrated, countValidFileSpecs(integratedFiles));

    //resolve files
    List<IFileSpec> resolvedFiles = resolveTestFilesAuto(client, integratedFiles);
    assertEquals("Number of files not integrated as expected.", expNumResolved, countValidFileSpecs(resolvedFiles));

    //update changelist and submit
    List<IFileSpec> submittedFiles = changelist.submit(false);
    dumpFileSpecInfo(submittedFiles, "FileSpecs returned from submit (after resolve)");

    //FIXME: Need verification routine to verify that the branch occurred and files exist.
    //verify files
    verifyTestFilesSubmitted(submittedFiles, expNumSubmitted);
    String[] actFinalFileList = getTestFileList(toFileStringBase);
    verifyIntegratedTestFiles(expFinalFileList, actFinalFileList);
}