• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Rename类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.fs.Options.Rename的典型用法代码示例。如果您正苦于以下问题:Java Rename类的具体用法?Java Rename怎么用?Java Rename使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Rename类属于org.apache.hadoop.fs.Options包,在下文中一共展示了Rename类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRenameDirectoryAsNonExistentDirectory

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
private void testRenameDirectoryAsNonExistentDirectory(Rename... options) throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fc, "test/hadoop/dir");
  fc.mkdir(src, FileContext.DEFAULT_PERM, true);
  createFile(getTestRootPath(fc, "test/hadoop/dir/file1"));
  createFile(getTestRootPath(fc, "test/hadoop/dir/subdir/file2"));
  
  Path dst = getTestRootPath(fc, "test/new/newdir");
  fc.mkdir(dst.getParent(), FileContext.DEFAULT_PERM, true);
  
  rename(src, dst, true, false, true, options);
  Assert.assertFalse("Nested file1 exists", 
      exists(fc, getTestRootPath(fc, "test/hadoop/dir/file1")));
  Assert.assertFalse("Nested file2 exists", 
      exists(fc, getTestRootPath(fc, "test/hadoop/dir/subdir/file2")));
  Assert.assertTrue("Renamed nested file1 exists",
      exists(fc, getTestRootPath(fc, "test/new/newdir/file1")));
  Assert.assertTrue("Renamed nested exists", 
      exists(fc, getTestRootPath(fc, "test/new/newdir/subdir/file2")));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:FileContextMainOperationsBaseTest.java


示例2: createCheckpoint

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
private void createCheckpoint(Path trashRoot, Date date) throws IOException {
  if (!fs.exists(new Path(trashRoot, CURRENT))) {
    return;
  }
  Path checkpointBase;
  synchronized (CHECKPOINT) {
    checkpointBase = new Path(trashRoot, CHECKPOINT.format(date));
  }
  Path checkpoint = checkpointBase;
  Path current = new Path(trashRoot, CURRENT);

  int attempt = 0;
  while (true) {
    try {
      fs.rename(current, checkpoint, Rename.NONE);
      LOG.info("Created trash checkpoint: " + checkpoint.toUri().getPath());
      break;
    } catch (FileAlreadyExistsException e) {
      if (++attempt > 1000) {
        throw new IOException("Failed to checkpoint trash: " + checkpoint);
      }
      checkpoint = checkpointBase.suffix("-" + attempt);
    }
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:26,代码来源:TrashPolicyDefault.java


示例3: testRenameFileAsExistingFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameFileAsExistingFile() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fc, "test/hadoop/file");
  createFile(src);
  Path dst = getTestRootPath(fc, "test/new/existingFile");
  createFile(dst);
  
  // Fails without overwrite option
  try {
    rename(src, dst, false, true, false, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
    Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  
  // Succeeds with overwrite option
  rename(src, dst, true, false, true, Rename.OVERWRITE);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:FileContextMainOperationsBaseTest.java


示例4: testRenameDirectoryAsEmptyDirectory

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameDirectoryAsEmptyDirectory() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fc, "test/hadoop/dir");
  fc.mkdir(src, FileContext.DEFAULT_PERM, true);
  createFile(getTestRootPath(fc, "test/hadoop/dir/file1"));
  createFile(getTestRootPath(fc, "test/hadoop/dir/subdir/file2"));
  
  Path dst = getTestRootPath(fc, "test/new/newdir");
  fc.mkdir(dst, FileContext.DEFAULT_PERM, true);

  // Fails without overwrite option
  try {
    rename(src, dst, false, true, false, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
    // Expected (cannot over-write non-empty destination)
    Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  // Succeeds with the overwrite option
  rename(src, dst, true, false, true, Rename.OVERWRITE);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:FileContextMainOperationsBaseTest.java


示例5: testRenameDirectoryAsFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameDirectoryAsFile() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fc, "test/hadoop/dir");
  fc.mkdir(src, FileContext.DEFAULT_PERM, true);
  Path dst = getTestRootPath(fc, "test/new/newfile");
  createFile(dst);
  // Fails without overwrite option
  try {
    rename(src, dst, false, true, true, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
  }
  // Directory cannot be renamed as existing file
  try {
    rename(src, dst, false, true, true, Rename.OVERWRITE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException ex) {
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:FileContextMainOperationsBaseTest.java


示例6: testCreateLinkUsingRelPaths

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test creating a symlink using relative paths */
public void testCreateLinkUsingRelPaths() throws IOException {
  Path fileAbs = new Path(testBaseDir1(), "file");
  Path linkAbs = new Path(testBaseDir1(), "linkToFile");
  Path schemeAuth = new Path(testURI().toString());
  Path fileQual = new Path(schemeAuth, testBaseDir1()+"/file");
  createAndWriteFile(fileAbs);

  wrapper.setWorkingDirectory(new Path(testBaseDir1()));
  wrapper.createSymlink(new Path("file"), new Path("linkToFile"), false);
  checkLink(linkAbs, new Path("file"), fileQual);

  // Now rename the link's parent. Because the target was specified
  // with a relative path the link should still resolve.
  Path dir1        = new Path(testBaseDir1());
  Path dir2        = new Path(testBaseDir2());
  Path linkViaDir2 = new Path(testBaseDir2(), "linkToFile");
  Path fileViaDir2 = new Path(schemeAuth, testBaseDir2()+"/file");
  wrapper.rename(dir1, dir2, Rename.OVERWRITE);
  FileStatus[] stats = wrapper.listStatus(dir2);
  assertEquals(fileViaDir2,
      wrapper.getFileLinkStatus(linkViaDir2).getSymlink());
  readFile(linkViaDir2);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:26,代码来源:SymlinkBaseTest.java


示例7: testCreateLinkUsingAbsPaths

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test creating a symlink using absolute paths */
public void testCreateLinkUsingAbsPaths() throws IOException {
  Path fileAbs = new Path(testBaseDir1()+"/file");
  Path linkAbs = new Path(testBaseDir1()+"/linkToFile");
  Path schemeAuth = new Path(testURI().toString());
  Path fileQual = new Path(schemeAuth, testBaseDir1()+"/file");
  createAndWriteFile(fileAbs);

  wrapper.createSymlink(fileAbs, linkAbs, false);
  checkLink(linkAbs, fileAbs, fileQual);

  // Now rename the link's parent. The target doesn't change and
  // now no longer exists so accessing the link should fail.
  Path dir1        = new Path(testBaseDir1());
  Path dir2        = new Path(testBaseDir2());
  Path linkViaDir2 = new Path(testBaseDir2(), "linkToFile");
  wrapper.rename(dir1, dir2, Rename.OVERWRITE);
  assertEquals(fileQual, wrapper.getFileLinkStatus(linkViaDir2).getSymlink());
  try {
    readFile(linkViaDir2);
    fail("The target should not exist");
  } catch (FileNotFoundException x) {
    // Expected
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:27,代码来源:SymlinkBaseTest.java


示例8: testRenameDirToSymlinkToDir

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a directory to a symlink to a directory */
public void testRenameDirToSymlinkToDir() throws IOException {
  Path dir1      = new Path(testBaseDir1());
  Path subDir = new Path(testBaseDir2(), "subDir");
  Path linkToDir = new Path(testBaseDir2(), "linkToDir");
  wrapper.mkdir(subDir, FileContext.DEFAULT_PERM, false);
  wrapper.createSymlink(subDir, linkToDir, false);
  try {
    wrapper.rename(dir1, linkToDir, Rename.OVERWRITE);
    fail("Renamed directory to a symlink");
  } catch (IOException e) {
    // Expected. Both must be directories.
    assertTrue(unwrapException(e) instanceof IOException);
  }
  assertTrue(wrapper.exists(dir1));
  assertTrue(wrapper.exists(linkToDir));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:SymlinkBaseTest.java


示例9: testRenameDirToSymlinkToFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a directory to a symlink to a file */
public void testRenameDirToSymlinkToFile() throws IOException {
  Path dir1 = new Path(testBaseDir1());
  Path file = new Path(testBaseDir2(), "file");
  Path linkToFile = new Path(testBaseDir2(), "linkToFile");
  createAndWriteFile(file);
  wrapper.createSymlink(file, linkToFile, false);
  try {
    wrapper.rename(dir1, linkToFile, Rename.OVERWRITE);
    fail("Renamed directory to a symlink");
  } catch (IOException e) {
    // Expected. Both must be directories.
    assertTrue(unwrapException(e) instanceof IOException);
  }
  assertTrue(wrapper.exists(dir1));
  assertTrue(wrapper.exists(linkToFile));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:SymlinkBaseTest.java


示例10: testRenameDirToDanglingSymlink

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a directory to a dangling symlink */
public void testRenameDirToDanglingSymlink() throws IOException {
  Path dir = new Path(testBaseDir1());
  Path link = new Path(testBaseDir2(), "linkToFile");
  wrapper.createSymlink(new Path("/doesNotExist"), link, false);
  try {
    wrapper.rename(dir, link, Rename.OVERWRITE);
    fail("Renamed directory to a symlink");
  } catch (IOException e) {
    // Expected. Both must be directories.
    assertTrue(unwrapException(e) instanceof IOException);
  }
  assertTrue(wrapper.exists(dir));
  assertTrue(wrapper.getFileLinkStatus(link) != null);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:SymlinkBaseTest.java


示例11: testRenameFileToSymlinkToDir

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a file to a symlink to a directory */
public void testRenameFileToSymlinkToDir() throws IOException {
  Path file   = new Path(testBaseDir1(), "file");
  Path subDir = new Path(testBaseDir1(), "subDir");
  Path link   = new Path(testBaseDir1(), "link");
  wrapper.mkdir(subDir, FileContext.DEFAULT_PERM, false);
  wrapper.createSymlink(subDir, link, false);
  createAndWriteFile(file);
  try {
    wrapper.rename(file, link);
    fail("Renamed file to symlink w/o overwrite");
  } catch (IOException e) {
    // Expected
    assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  wrapper.rename(file, link, Rename.OVERWRITE);
  assertFalse(wrapper.exists(file));
  assertTrue(wrapper.exists(link));
  assertTrue(wrapper.isFile(link));
  assertFalse(wrapper.getFileLinkStatus(link).isSymlink());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:SymlinkBaseTest.java


示例12: testRenameFileToSymlinkToFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a file to a symlink to a file */
public void testRenameFileToSymlinkToFile() throws IOException {
  Path file1 = new Path(testBaseDir1(), "file1");
  Path file2 = new Path(testBaseDir1(), "file2");
  Path link = new Path(testBaseDir1(), "linkToFile");
  createAndWriteFile(file1);
  createAndWriteFile(file2);
  wrapper.createSymlink(file2, link, false);
  try {
    wrapper.rename(file1, link);
    fail("Renamed file to symlink w/o overwrite");
  } catch (IOException e) {
    // Expected
    assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  wrapper.rename(file1, link, Rename.OVERWRITE);
  assertFalse(wrapper.exists(file1));
  assertTrue(wrapper.exists(link));
  assertTrue(wrapper.isFile(link));
  assertFalse(wrapper.getFileLinkStatus(link).isSymlink());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:SymlinkBaseTest.java


示例13: testRenameFileToDanglingSymlink

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename a file to a dangling symlink */
public void testRenameFileToDanglingSymlink() throws IOException {
  /* NB: Local file system doesn't handle dangling links correctly
   * since File.exists(danglinLink) returns false. */
  if ("file".equals(getScheme())) {
    return;
  }
  Path file1 = new Path(testBaseDir1(), "file1");
  Path link = new Path(testBaseDir1(), "linkToFile");
  createAndWriteFile(file1);
  wrapper.createSymlink(new Path("/doesNotExist"), link, false);
  try {
    wrapper.rename(file1, link);
  } catch (IOException e) {
    // Expected
  }
  wrapper.rename(file1, link, Rename.OVERWRITE);
  assertFalse(wrapper.exists(file1));
  assertTrue(wrapper.exists(link));
  assertTrue(wrapper.isFile(link));
  assertFalse(wrapper.getFileLinkStatus(link).isSymlink());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:SymlinkBaseTest.java


示例14: testRenameSymlinkToExistingFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Rename a symlink to a file that exists */
public void testRenameSymlinkToExistingFile() throws IOException {
  Path file1 = new Path(testBaseDir1(), "file");
  Path file2 = new Path(testBaseDir1(), "someFile");
  Path link = new Path(testBaseDir1(), "linkToFile");
  createAndWriteFile(file1);
  createAndWriteFile(file2);
  wrapper.createSymlink(file2, link, false);
  try {
    wrapper.rename(link, file1);
    fail("Renamed w/o passing overwrite");
  } catch (IOException e) {
    // Expected
    assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  wrapper.rename(link, file1, Rename.OVERWRITE);
  assertFalse(wrapper.exists(link));
  assertTrue(wrapper.getFileLinkStatus(file1).isSymlink());
  assertEquals(file2, wrapper.getLinkTarget(file1));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:SymlinkBaseTest.java


示例15: testRenameLinkTarget

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test(timeout=10000)
/** Test rename the symlink's target */
public void testRenameLinkTarget() throws IOException {
  Path file    = new Path(testBaseDir1(), "file");
  Path fileNew = new Path(testBaseDir1(), "fileNew");
  Path link    = new Path(testBaseDir1(), "linkToFile");
  createAndWriteFile(file);
  wrapper.createSymlink(file, link, false);
  wrapper.rename(file, fileNew, Rename.OVERWRITE);
  try {
    readFile(link);
    fail("Link should be dangling");
  } catch (IOException x) {
    // Expected
  }
  wrapper.rename(fileNew, file, Rename.OVERWRITE);
  readFile(link);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:SymlinkBaseTest.java


示例16: testRenameFileAsExistingFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameFileAsExistingFile() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fSys, "test/hadoop/file");
  createFile(src);
  Path dst = getTestRootPath(fSys, "test/new/existingFile");
  createFile(dst);
  
  // Fails without overwrite option
  try {
    rename(src, dst, false, true, false, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
    Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  
  // Succeeds with overwrite option
  rename(src, dst, true, false, true, Rename.OVERWRITE);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:FSMainOperationsBaseTest.java


示例17: doTestRenameDirectoryAsNonExistentDirectory

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
private void doTestRenameDirectoryAsNonExistentDirectory(Rename... options) 
throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fSys, "test/hadoop/dir");
  fSys.mkdirs(src);
  createFile(getTestRootPath(fSys, "test/hadoop/dir/file1"));
  createFile(getTestRootPath(fSys, "test/hadoop/dir/subdir/file2"));
  
  Path dst = getTestRootPath(fSys, "test/new/newdir");
  fSys.mkdirs(dst.getParent());
  
  rename(src, dst, true, false, true, options);
  Assert.assertFalse("Nested file1 exists", 
      exists(fSys, getTestRootPath(fSys, "test/hadoop/dir/file1")));
  Assert.assertFalse("Nested file2 exists", 
      exists(fSys, getTestRootPath(fSys, "test/hadoop/dir/subdir/file2")));
  Assert.assertTrue("Renamed nested file1 exists",
      exists(fSys, getTestRootPath(fSys, "test/new/newdir/file1")));
  Assert.assertTrue("Renamed nested exists", 
      exists(fSys, getTestRootPath(fSys, "test/new/newdir/subdir/file2")));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:FSMainOperationsBaseTest.java


示例18: testRenameDirectoryAsEmptyDirectory

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameDirectoryAsEmptyDirectory() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fSys, "test/hadoop/dir");
  fSys.mkdirs(src);
  createFile(getTestRootPath(fSys, "test/hadoop/dir/file1"));
  createFile(getTestRootPath(fSys, "test/hadoop/dir/subdir/file2"));
  
  Path dst = getTestRootPath(fSys, "test/new/newdir");
  fSys.mkdirs(dst);

  // Fails without overwrite option
  try {
    rename(src, dst, false, true, false, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
    // Expected (cannot over-write non-empty destination)
    Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException);
  }
  // Succeeds with the overwrite option
  rename(src, dst, true, false, true, Rename.OVERWRITE);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:FSMainOperationsBaseTest.java


示例19: testRenameDirectoryAsFile

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Test
public void testRenameDirectoryAsFile() throws Exception {
  if (!renameSupported()) return;
  
  Path src = getTestRootPath(fSys, "test/hadoop/dir");
  fSys.mkdirs(src);
  Path dst = getTestRootPath(fSys, "test/new/newfile");
  createFile(dst);
  // Fails without overwrite option
  try {
    rename(src, dst, false, true, true, Rename.NONE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException e) {
  }
  // Directory cannot be renamed as existing file
  try {
    rename(src, dst, false, true, true, Rename.OVERWRITE);
    Assert.fail("Expected exception was not thrown");
  } catch (IOException ex) {
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:FSMainOperationsBaseTest.java


示例20: toXml

import org.apache.hadoop.fs.Options.Rename; //导入依赖的package包/类
@Override
protected void toXml(ContentHandler contentHandler) throws SAXException {
  XMLUtils.addSaxString(contentHandler, "LENGTH",
      Integer.toString(length));
  XMLUtils.addSaxString(contentHandler, "SRC", src);
  XMLUtils.addSaxString(contentHandler, "DST", dst);
  XMLUtils.addSaxString(contentHandler, "TIMESTAMP",
      Long.toString(timestamp));
  StringBuilder bld = new StringBuilder();
  String prefix = "";
  for (Rename r : options) {
    bld.append(prefix).append(r.toString());
    prefix = "|";
  }
  XMLUtils.addSaxString(contentHandler, "OPTIONS", bld.toString());
  appendRpcIdsToXml(contentHandler, rpcClientId, rpcCallId);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:FSEditLogOp.java



注:本文中的org.apache.hadoop.fs.Options.Rename类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CompositePipe类代码示例发布时间:2022-05-21
下一篇:
Java SizeF类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap