Java Code Examples for org.apache.hadoop.util.Shell#isJava7OrAbove()

The following examples show how to use org.apache.hadoop.util.Shell#isJava7OrAbove() . 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: ContainerLaunch.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void link(Path src, Path dst) throws IOException {
  File srcFile = new File(src.toUri().getPath());
  String srcFileStr = srcFile.getPath();
  String dstFileStr = new File(dst.toString()).getPath();
  // If not on Java7+ on Windows, then copy file instead of symlinking.
  // See also FileUtil#symLink for full explanation.
  if (!Shell.isJava7OrAbove() && srcFile.isFile()) {
    lineWithLenCheck(String.format("@copy \"%s\" \"%s\"", srcFileStr, dstFileStr));
    errorCheck();
  } else {
    lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", Shell.WINUTILS,
      dstFileStr, srcFileStr));
    errorCheck();
  }
}
 
Example 2
Source File: ContainerLaunch.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void link(Path src, Path dst) throws IOException {
  File srcFile = new File(src.toUri().getPath());
  String srcFileStr = srcFile.getPath();
  String dstFileStr = new File(dst.toString()).getPath();
  // If not on Java7+ on Windows, then copy file instead of symlinking.
  // See also FileUtil#symLink for full explanation.
  if (!Shell.isJava7OrAbove() && srcFile.isFile()) {
    lineWithLenCheck(String.format("@copy \"%s\" \"%s\"", srcFileStr, dstFileStr));
    errorCheck();
  } else {
    lineWithLenCheck(String.format("@%s symlink \"%s\" \"%s\"", Shell.WINUTILS,
      dstFileStr, srcFileStr));
    errorCheck();
  }
}
 
Example 3
Source File: TestFileUtil.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Test that length on a symlink works as expected.
 */
@Test (timeout = 30000)
public void testSymlinkLength() throws Exception {
  Assert.assertFalse(del.exists());
  del.mkdirs();

  byte[] data = "testSymLinkData".getBytes();

  File file = new File(del, FILE);
  File link = new File(del, "_link");

  // write some data to the file
  FileOutputStream os = new FileOutputStream(file);
  os.write(data);
  os.close();

  Assert.assertEquals(0, link.length());

  // create the symlink
  FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());

  // ensure that File#length returns the target file and link size
  Assert.assertEquals(data.length, file.length());
  Assert.assertEquals(data.length, link.length());

  file.delete();
  Assert.assertFalse(file.exists());

  if (Shell.WINDOWS && !Shell.isJava7OrAbove()) {
    // On Java6 on Windows, we copied the file
    Assert.assertEquals(data.length, link.length());
  } else {
    // Otherwise, the target file size is zero
    Assert.assertEquals(0, link.length());
  }

  link.delete();
  Assert.assertFalse(link.exists());
}
 
Example 4
Source File: TestSymlinkLocalFS.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean emulatingSymlinksOnWindows() {
  // Java 6 on Windows has very poor symlink support. Specifically
  // Specifically File#length and File#renameTo do not work as expected.
  // (see HADOOP-9061 for additional details)
  // Hence some symlink tests will be skipped.
  //
  return (Shell.WINDOWS && !Shell.isJava7OrAbove());
}
 
Example 5
Source File: TestFileUtil.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Test that length on a symlink works as expected.
 */
@Test (timeout = 30000)
public void testSymlinkLength() throws Exception {
  Assert.assertFalse(del.exists());
  del.mkdirs();

  byte[] data = "testSymLinkData".getBytes();

  File file = new File(del, FILE);
  File link = new File(del, "_link");

  // write some data to the file
  FileOutputStream os = new FileOutputStream(file);
  os.write(data);
  os.close();

  Assert.assertEquals(0, link.length());

  // create the symlink
  FileUtil.symLink(file.getAbsolutePath(), link.getAbsolutePath());

  // ensure that File#length returns the target file and link size
  Assert.assertEquals(data.length, file.length());
  Assert.assertEquals(data.length, link.length());

  file.delete();
  Assert.assertFalse(file.exists());

  if (Shell.WINDOWS && !Shell.isJava7OrAbove()) {
    // On Java6 on Windows, we copied the file
    Assert.assertEquals(data.length, link.length());
  } else {
    // Otherwise, the target file size is zero
    Assert.assertEquals(0, link.length());
  }

  link.delete();
  Assert.assertFalse(link.exists());
}
 
Example 6
Source File: TestSymlinkLocalFS.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean emulatingSymlinksOnWindows() {
  // Java 6 on Windows has very poor symlink support. Specifically
  // Specifically File#length and File#renameTo do not work as expected.
  // (see HADOOP-9061 for additional details)
  // Hence some symlink tests will be skipped.
  //
  return (Shell.WINDOWS && !Shell.isJava7OrAbove());
}