org.eclipse.jgit.util.FileUtils类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中org.eclipse.jgit.util.FileUtils类的一些代码示例,展示了FileUtils类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils类的具体详情如下:
包路径:org.eclipse.jgit.util.FileUtils
类名称:FileUtils

FileUtils介绍

[英]File Utilities
[中]文件应用

代码示例

代码示例来源:origin: spring-cloud/spring-cloud-config

public static String prepareLocalSvnRepo(String sourceDir, String checkoutDir) throws Exception {
  File sourceDirFile = new File(sourceDir);
  sourceDirFile.mkdirs();
  File local = new File(checkoutDir);
  if (local.exists()) {
    FileUtils.delete(local, FileUtils.RECURSIVE);
  }
  local.mkdirs();
  FileSystemUtils.copyRecursively(sourceDirFile, local);
  return StringUtils.cleanPath("file:///" + local.getAbsolutePath());
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Creates the directory named by this abstract pathname, including any
 * necessary but nonexistent parent directories. Note that if this operation
 * fails it may have succeeded in creating some of the necessary parent
 * directories.
 *
 * @param d
 *            directory to be created
 * @throws java.io.IOException
 *             if creation of {@code d} fails. This may occur if {@code d}
 *             did exist when the method was called. This can therefore
 *             cause java.io.IOExceptions during race conditions when
 *             multiple concurrent threads all try to create the same
 *             directory.
 */
public static void mkdirs(File d) throws IOException {
  mkdirs(d, false);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

private File getFile(String path, boolean create)
    throws PatchApplyException {
  File f = new File(getRepository().getWorkTree(), path);
  if (create)
    try {
      File parent = f.getParentFile();
      FileUtils.mkdirs(parent, true);
      FileUtils.createNewFile(f);
    } catch (IOException e) {
      throw new PatchApplyException(MessageFormat.format(
          JGitText.get().createNewFileFailed, f), e);
    }
  return f;
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/** {@inheritDoc} */
@Override
public void create() throws IOException {
  FileUtils.mkdirs(objects);
  FileUtils.mkdir(infoDirectory);
  FileUtils.mkdir(packDirectory);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Deletes old pack file, unless 'preserve-oldpacks' is set, in which case it
 * moves the pack file to the preserved directory
 *
 * @param packFile
 * @param packName
 * @param ext
 * @param deleteOptions
 * @throws IOException
 */
private void removeOldPack(File packFile, String packName, PackExt ext,
    int deleteOptions) throws IOException {
  if (pconfig != null && pconfig.isPreserveOldPacks()) {
    File oldPackDir = repo.getObjectDatabase().getPreservedDirectory();
    FileUtils.mkdir(oldPackDir, true);
    String oldPackName = "pack-" + packName + ".old-" + ext.getExtension();  //$NON-NLS-1$ //$NON-NLS-2$
    File oldPackFile = new File(oldPackDir, oldPackName);
    FileUtils.rename(packFile, oldPackFile);
  } else {
    FileUtils.delete(packFile, deleteOptions);
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

File f = new File(repo.getWorkTree(), entry.getPathString());
File parentDir = f.getParentFile();
FileUtils.mkdirs(parentDir, true);
FS fs = repo.getFS();
WorkingTreeOptions opt = repo.getConfig().get(WorkingTreeOptions.KEY);
  String target = RawParseUtils.decode(bytes);
  if (deleteRecursive && f.isDirectory()) {
    FileUtils.delete(f, FileUtils.RECURSIVE);
    FileUtils.delete(f, FileUtils.RECURSIVE);
  FileUtils.rename(tmpFile, f, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
  throw new IOException(
} finally {
  if (tmpFile.exists()) {
    FileUtils.delete(tmpFile);

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

JGitText.get().repositoryAlreadyExists, getDirectory()));
FileUtils.mkdirs(getDirectory(), true);
HideDotFiles hideDotFiles = getConfig().getEnum(
    ConfigConstants.CONFIG_CORE_SECTION, null,
objectDatabase.create();
FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$
FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$
  FileUtils.delete(tmp);
    getFS().createSymLink(tmp, "target"); //$NON-NLS-1$
    symLinks = null;
    FileUtils.delete(tmp);
  } catch (IOException e) {

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

@Override
  public RemoteFile readFileWithMode(String uri, String ref, String path)
      throws GitAPIException, IOException {
    File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
    try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
        .setURI(uri).call()) {
      Repository repo = git.getRepository();
      ObjectId refCommitId = sha1(uri, ref);
      if (refCommitId == null) {
        throw new InvalidRefNameException(MessageFormat
            .format(JGitText.get().refNotResolved, ref));
      }
      RevCommit commit = repo.parseCommit(refCommitId);
      TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree());
      // TODO(ifrade): Cope better with big files (e.g. using
      // InputStream instead of byte[])
      return new RemoteFile(
          tw.getObjectReader().open(tw.getObjectId(0))
              .getCachedBytes(Integer.MAX_VALUE),
          tw.getFileMode(0));
    } finally {
      FileUtils.delete(dir, FileUtils.RECURSIVE);
    }
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

FileUtils.delete(tmp, FileUtils.RETRY);
  return InsertLooseObjectResult.EXISTS_LOOSE;
  FileUtils.delete(tmp, FileUtils.RETRY);
  return InsertLooseObjectResult.EXISTS_PACKED;
  FileUtils.delete(tmp, FileUtils.RETRY);
  return InsertLooseObjectResult.EXISTS_LOOSE;
  Files.move(FileUtils.toPath(tmp), FileUtils.toPath(dst),
      StandardCopyOption.ATOMIC_MOVE);
  dst.setReadOnly();
FileUtils.mkdir(dst.getParentFile(), true);
try {
  Files.move(FileUtils.toPath(tmp), FileUtils.toPath(dst),
      StandardCopyOption.ATOMIC_MOVE);
  dst.setReadOnly();
  FileUtils.delete(tmp, FileUtils.RETRY);
  return InsertLooseObjectResult.EXISTS_PACKED;
FileUtils.delete(tmp, FileUtils.RETRY);
return InsertLooseObjectResult.FAILURE;

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a symbolic link
 *
 * @param path
 *            the path of the symbolic link to create
 * @param target
 *            the target of the symbolic link
 * @return the path to the symbolic link
 * @throws java.io.IOException
 * @since 4.2
 */
public static Path createSymLink(File path, String target)
    throws IOException {
  Path nioPath = toPath(path);
  if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) {
    BasicFileAttributes attrs = Files.readAttributes(nioPath,
        BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
    if (attrs.isRegularFile() || attrs.isSymbolicLink()) {
      delete(path);
    } else {
      delete(path, EMPTY_DIRECTORIES_ONLY | RECURSIVE);
    }
  }
  if (SystemReader.getInstance().isWindows()) {
    target = target.replace('/', '\\');
  }
  Path nioTarget = toPath(new File(target));
  return Files.createSymbolicLink(nioPath, nioTarget);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

FileUtils.rename(tmpPack, finalPack,
      StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
  FileUtils.rename(tmpIdx, finalIdx, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
  cleanupTemporaryFiles();
  keep.unlock();
  if (finalPack.exists())
    FileUtils.delete(finalPack);
  if (finalIdx.exists())
    FileUtils.delete(finalIdx);
  throw err;

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

FileUtils.mkdir(rebaseState.getDir(), true);
} finally {
  if (!checkoutOk)
    FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE);

代码示例来源:origin: org.eclipse.egit/ui

try {
  if (!file.exists())
    FileUtils.createNewFile(file);
  out = new FileOutputStream(file);
  out.write(getContent());

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Check if a file is a symbolic link and read it
 *
 * @param path
 *            a {@link java.io.File} object.
 * @return target of link or null
 * @throws java.io.IOException
 * @since 3.0
 */
public String readSymLink(File path) throws IOException {
  return FileUtils.readSymLink(path);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Create a symbolic link
 *
 * @param path
 *            a {@link java.io.File} object.
 * @param target
 *            target path of the symlink
 * @throws java.io.IOException
 * @since 3.0
 */
public void createSymLink(File path, String target) throws IOException {
  FileUtils.createSymLink(path, target);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * @param fs
 * @param file
 * @return non null attributes object
 */
static Attributes getFileAttributesBasic(FS fs, File file) {
  try {
    Path nioPath = toPath(file);
    BasicFileAttributes readAttributes = nioPath
        .getFileSystem()
        .provider()
        .getFileAttributeView(nioPath,
            BasicFileAttributeView.class,
            LinkOption.NOFOLLOW_LINKS).readAttributes();
    Attributes attributes = new Attributes(fs, file,
        true,
        readAttributes.isDirectory(),
        fs.supportsExecute() ? file.canExecute() : false,
        readAttributes.isSymbolicLink(),
        readAttributes.isRegularFile(), //
        readAttributes.creationTime().toMillis(), //
        readAttributes.lastModifiedTime().toMillis(),
        readAttributes.isSymbolicLink() ? Constants
            .encode(readSymLink(file)).length
            : readAttributes.size());
    return attributes;
  } catch (IOException e) {
    return new Attributes(file, fs);
  }
}

代码示例来源:origin: beijunyi/ParallelGit

protected void initRepositoryDir() throws IOException {
 if(repoDir == null)
  repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null);
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit.lfs

throw new CorruptMediaFile(mediaFile, size, fsSize);
} else {
  FileUtils.delete(tmpFile.toFile());
  FileUtils.mkdirs(parent.toFile(), true);
FileUtils.rename(tmpFile.toFile(), mediaFile.toFile(),
    StandardCopyOption.ATOMIC_MOVE);

代码示例来源:origin: sonia.jgit/org.eclipse.jgit

JGitText.get().repositoryAlreadyExists, getDirectory()));
FileUtils.mkdirs(getDirectory(), true);
HideDotFiles hideDotFiles = getConfig().getEnum(
    ConfigConstants.CONFIG_CORE_SECTION, null,
objectDatabase.create();
FileUtils.mkdir(new File(getDirectory(), "branches")); //$NON-NLS-1$
FileUtils.mkdir(new File(getDirectory(), "hooks")); //$NON-NLS-1$
  FileUtils.delete(tmp);
    getFS().createSymLink(tmp, "target"); //$NON-NLS-1$
    symLinks = null;
    FileUtils.delete(tmp);
  } catch (IOException e) {

代码示例来源:origin: sonia.jgit/org.eclipse.jgit

public byte[] readFile(String uri, String ref, String path)
    throws GitAPIException, IOException {
  File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
  Repository repo = Git
      .cloneRepository()
      .setBare(true)
      .setDirectory(dir)
      .setURI(uri)
      .call()
      .getRepository();
  try {
    return readFileFromRepo(repo, ref, path);
  } finally {
    repo.close();
    FileUtils.delete(dir, FileUtils.RECURSIVE);
  }
}

相关文章