當前位置: 首頁>>代碼示例>>Java>>正文


Java FileAlreadyExistsException類代碼示例

本文整理匯總了Java中org.apache.hadoop.fs.FileAlreadyExistsException的典型用法代碼示例。如果您正苦於以下問題:Java FileAlreadyExistsException類的具體用法?Java FileAlreadyExistsException怎麽用?Java FileAlreadyExistsException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FileAlreadyExistsException類屬於org.apache.hadoop.fs包,在下文中一共展示了FileAlreadyExistsException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateDestination

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
private static void validateDestination(
    String src, String dst, INode srcInode)
    throws IOException {
  String error;
  if (srcInode.isSymlink() &&
      dst.equals(srcInode.asSymlink().getSymlinkString())) {
    throw new FileAlreadyExistsException("Cannot rename symlink " + src
        + " to its target " + dst);
  }
  // dst cannot be a directory or a file under src
  if (dst.startsWith(src)
      && dst.charAt(src.length()) == Path.SEPARATOR_CHAR) {
    error = "Rename destination " + dst
        + " is a directory or file under source " + src;
    NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: "
        + error);
    throw new IOException(error);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:FSDirRenameOp.java

示例2: create

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
/**
 * @param permission Currently ignored.
 */
@Override
public FSDataOutputStream create(Path file, FsPermission permission,
    boolean overwrite, int bufferSize,
    short replication, long blockSize, Progressable progress)
  throws IOException {

  INode inode = store.retrieveINode(makeAbsolute(file));
  if (inode != null) {
    if (overwrite) {
      delete(file, true);
    } else {
      throw new FileAlreadyExistsException("File already exists: " + file);
    }
  } else {
    Path parent = file.getParent();
    if (parent != null) {
      if (!mkdirs(parent)) {
        throw new IOException("Mkdirs failed to create " + parent.toString());
      }
    }      
  }
  return new FSDataOutputStream
      (new S3OutputStream(getConf(), store, makeAbsolute(file),
                          blockSize, progress, bufferSize),
       statistics);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:S3FileSystem.java

示例3: createInternal

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
@Override
public FSDataOutputStream createInternal(final Path f,
    final EnumSet<CreateFlag> flag, final FsPermission absolutePermission,
    final int bufferSize, final short replication, final long blockSize,
    final Progressable progress, final ChecksumOpt checksumOpt,
    final boolean createParent) throws AccessControlException,
    FileAlreadyExistsException, FileNotFoundException,
    ParentNotDirectoryException, UnsupportedFileSystemException,
    UnresolvedLinkException, IOException {
  InodeTree.ResolveResult<AbstractFileSystem> res;
  try {
    res = fsState.resolve(getUriPath(f), false);
  } catch (FileNotFoundException e) {
    if (createParent) {
      throw readOnlyMountTable("create", f);
    } else {
      throw e;
    }
  }
  assert(res.remainingPath != null);
  return res.targetFileSystem.createInternal(res.remainingPath, flag,
      absolutePermission, bufferSize, replication,
      blockSize, progress, checksumOpt,
      createParent);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:26,代碼來源:ViewFs.java

示例4: testCreateFileOverExistingFileNoOverwrite

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
@Test
public void testCreateFileOverExistingFileNoOverwrite() throws Throwable {
  describe("Verify overwriting an existing file fails");
  Path path = path("testCreateFileOverExistingFileNoOverwrite");
  byte[] data = dataset(256, 'a', 'z');
  writeDataset(getFileSystem(), path, data, data.length, 1024, false);
  byte[] data2 = dataset(10 * 1024, 'A', 'Z');
  try {
    writeDataset(getFileSystem(), path, data2, data2.length, 1024, false);
    fail("writing without overwrite unexpectedly succeeded");
  } catch (FileAlreadyExistsException expected) {
    //expected
    handleExpectedException(expected);
  } catch (IOException relaxed) {
    handleRelaxedException("Creating a file over a file with overwrite==false",
                           "FileAlreadyExistsException",
                           relaxed);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:AbstractContractCreateTest.java

示例5: zkSet

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
/**
 * Create or update an entry
 * @param path path
 * @param data data
 * @param acl ACL for path -used when creating a new entry
 * @param overwrite enable overwrite
 * @throws IOException
 * @return true if the entry was created, false if it was simply updated.
 */
public boolean zkSet(String path,
    CreateMode mode,
    byte[] data,
    List<ACL> acl, boolean overwrite) throws IOException {
  Preconditions.checkArgument(data != null, "null data");
  checkServiceLive();
  if (!zkPathExists(path)) {
    zkCreate(path, mode, data, acl);
    return true;
  } else {
    if (overwrite) {
      zkUpdate(path, data);
      return false;
    } else {
      throw new FileAlreadyExistsException(path);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:28,代碼來源:CuratorService.java

示例6: testOverwrite

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
@Test
public void testOverwrite() throws Throwable {
  ServiceRecord written = putExampleServiceEntry(ENTRY_PATH, 0);
  ServiceRecord resolved1 = operations.resolve(ENTRY_PATH);
  resolved1.description = "resolved1";
  try {
    operations.bind(ENTRY_PATH, resolved1, 0);
    fail("overwrite succeeded when it should have failed");
  } catch (FileAlreadyExistsException expected) {
    // expected
  }

  // verify there's no changed
  ServiceRecord resolved2 = operations.resolve(ENTRY_PATH);
  assertMatches(written, resolved2);
  operations.bind(ENTRY_PATH, resolved1, BindFlags.OVERWRITE);
  ServiceRecord resolved3 = operations.resolve(ENTRY_PATH);
  assertMatches(resolved1, resolved3);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestRegistryOperations.java

示例7: mkdir

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
private void mkdir(FileSystem fs, Path path, FsPermission fsp)
    throws IOException {
  if (!fs.exists(path)) {
    try {
      fs.mkdirs(path, fsp);
      FileStatus fsStatus = fs.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        fs.setPermission(path, fsp);
      }
    } catch (FileAlreadyExistsException e) {
      LOG.info("Directory: [" + path + "] already exists.");
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:JobHistoryEventHandler.java

示例8: mkdir

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
private void mkdir(FileContext fc, Path path, FsPermission fsp)
    throws IOException {
  if (!fc.util().exists(path)) {
    try {
      fc.mkdir(path, fsp, true);

      FileStatus fsStatus = fc.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        fc.setPermission(path, fsp);
      }
    } catch (FileAlreadyExistsException e) {
      LOG.info("Directory: [" + path + "] already exists.");
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:HistoryFileManager.java

示例9: makeDoneSubdir

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
private void makeDoneSubdir(Path path) throws IOException {
  try {
    doneDirFc.getFileStatus(path);
    existingDoneSubdirs.add(path);
  } catch (FileNotFoundException fnfE) {
    try {
      FsPermission fsp = new FsPermission(
          JobHistoryUtils.HISTORY_DONE_DIR_PERMISSION);
      doneDirFc.mkdir(path, fsp, true);
      FileStatus fsStatus = doneDirFc.getFileStatus(path);
      LOG.info("Perms after creating " + fsStatus.getPermission().toShort()
          + ", Expected: " + fsp.toShort());
      if (fsStatus.getPermission().toShort() != fsp.toShort()) {
        LOG.info("Explicitly setting permissions to : " + fsp.toShort()
            + ", " + fsp);
        doneDirFc.setPermission(path, fsp);
      }
      existingDoneSubdirs.add(path);
    } catch (FileAlreadyExistsException faeE) { // Nothing to do.
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:HistoryFileManager.java

示例10: createSymlink

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
/**
 * Creates a symbolic link.
 * 
 * @see ClientProtocol#createSymlink(String, String,FsPermission, boolean) 
 */
public void createSymlink(String target, String link, boolean createParent)
    throws IOException {
  TraceScope scope = getPathTraceScope("createSymlink", target);
  try {
    FsPermission dirPerm = 
        FsPermission.getDefault().applyUMask(dfsClientConf.uMask); 
    namenode.createSymlink(target, link, dirPerm, createParent);
  } catch (RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   FileAlreadyExistsException.class, 
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   NSQuotaExceededException.class, 
                                   DSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  } finally {
    scope.close();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:DFSClient.java

示例11: rename

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
/**
 * Rename file or directory.
 * @see ClientProtocol#rename2(String, String, Options.Rename...)
 */
public void rename(String src, String dst, Options.Rename... options)
    throws IOException {
  checkOpen();
  TraceScope scope = getSrcDstTraceScope("rename2", src, dst);
  try {
    namenode.rename2(src, dst, options);
  } catch(RemoteException re) {
    throw re.unwrapRemoteException(AccessControlException.class,
                                   DSQuotaExceededException.class,
                                   FileAlreadyExistsException.class,
                                   FileNotFoundException.class,
                                   ParentNotDirectoryException.class,
                                   SafeModeException.class,
                                   NSQuotaExceededException.class,
                                   UnresolvedPathException.class,
                                   SnapshotAccessControlException.class);
  } finally {
    scope.close();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:DFSClient.java

示例12: startFile

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
/**
 * Create a new file entry in the namespace.
 * 
 * For description of parameters and exceptions thrown see
 * {@link ClientProtocol#create}, except it returns valid file status upon
 * success
 */
HdfsFileStatus startFile(String src, PermissionStatus permissions,
    String holder, String clientMachine, EnumSet<CreateFlag> flag,
    boolean createParent, short replication, long blockSize, 
    CryptoProtocolVersion[] supportedVersions, boolean logRetryCache)
    throws AccessControlException, SafeModeException,
    FileAlreadyExistsException, UnresolvedLinkException,
    FileNotFoundException, ParentNotDirectoryException, IOException {

  HdfsFileStatus status = null;
  try {
    status = startFileInt(src, permissions, holder, clientMachine, flag,
        createParent, replication, blockSize, supportedVersions,
        logRetryCache);
  } catch (AccessControlException e) {
    logAuditEvent(false, "create", src);
    throw e;
  }
  return status;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:FSNamesystem.java

示例13: unprotectedMkdir

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
/**
 * create a directory at path specified by parent
 */
private static INodesInPath unprotectedMkdir(FSDirectory fsd, long inodeId,
    INodesInPath parent, byte[] name, PermissionStatus permission,
    List<AclEntry> aclEntries, long timestamp)
    throws QuotaExceededException, AclException, FileAlreadyExistsException {
  assert fsd.hasWriteLock();
  assert parent.getLastINode() != null;
  if (!parent.getLastINode().isDirectory()) {
    throw new FileAlreadyExistsException("Parent path is not a directory: " +
        parent.getPath() + " " + DFSUtil.bytes2String(name));
  }
  final INodeDirectory dir = new INodeDirectory(inodeId, name, permission,
      timestamp);

  INodesInPath iip = fsd.addLastINode(parent, dir, true);
  if (iip != null && aclEntries != null) {
    AclStorage.updateINodeAcl(dir, aclEntries, Snapshot.CURRENT_STATE_ID);
  }
  return iip;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:FSDirMkdirOp.java

示例14: rename2

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
@Override
public void rename2(String src, String dst, Rename... options)
    throws AccessControlException, DSQuotaExceededException,
    FileAlreadyExistsException, FileNotFoundException,
    NSQuotaExceededException, ParentNotDirectoryException, SafeModeException,
    UnresolvedLinkException, IOException {
  boolean overwrite = false;
  if (options != null) {
    for (Rename option : options) {
      if (option == Rename.OVERWRITE) {
        overwrite = true;
      }
    }
  }
  Rename2RequestProto req = Rename2RequestProto.newBuilder().
      setSrc(src).
      setDst(dst).setOverwriteDest(overwrite).
      build();
  try {
    rpcProxy.rename2(null, req);
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:ClientNamenodeProtocolTranslatorPB.java

示例15: mkdirs

import org.apache.hadoop.fs.FileAlreadyExistsException; //導入依賴的package包/類
@Override
public boolean mkdirs(String src, FsPermission masked, boolean createParent)
    throws AccessControlException, FileAlreadyExistsException,
    FileNotFoundException, NSQuotaExceededException,
    ParentNotDirectoryException, SafeModeException, UnresolvedLinkException,
    IOException {
  MkdirsRequestProto req = MkdirsRequestProto.newBuilder()
      .setSrc(src)
      .setMasked(PBHelper.convert(masked))
      .setCreateParent(createParent).build();

  try {
    return rpcProxy.mkdirs(null, req).getResult();
  } catch (ServiceException e) {
    throw ProtobufHelper.getRemoteException(e);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:ClientNamenodeProtocolTranslatorPB.java


注:本文中的org.apache.hadoop.fs.FileAlreadyExistsException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。