Java Code Examples for com.intellij.openapi.util.io.FileUtil#createParentDirs()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#createParentDirs() . 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: PersistentMapTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void test2GLimit() throws IOException {
  if (!DO_SLOW_TEST) return;
  File file = FileUtil.createTempFile("persistent", "map");
  FileUtil.createParentDirs(file);
  EnumeratorStringDescriptor stringDescriptor = new EnumeratorStringDescriptor();
  PersistentHashMap<String, String> map = new PersistentHashMap<String, String>(file, stringDescriptor, stringDescriptor);
  for (int i = 0; i < 12000; i++) {
    map.put("abc" + i, StringUtil.repeat("0123456789", 10000));
  }
  map.close();

  map = new PersistentHashMap<String, String>(file,
                                              stringDescriptor, stringDescriptor);
  long len = 0;
  for (String key : map.getAllKeysWithExistingMapping()) {
    len += map.get(key).length();
  }
  map.close();
  assertEquals(1200000000L, len);
}
 
Example 2
Source File: ArtifactsCompilerInstance.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void extractFile(VirtualFile sourceFile, File toFile, Set<String> writtenPaths, FileFilter fileFilter) throws IOException {
  if (!writtenPaths.add(toFile.getPath())) {
    return;
  }

  if (!FileUtil.createParentDirs(toFile)) {
    myContext.addMessage(CompilerMessageCategory.ERROR, "Cannot create directory for '" + toFile.getAbsolutePath() + "' file", null, -1, -1);
    return;
  }

  InputStream input = ArtifactCompilerUtil.getArchiveEntryInputStream(sourceFile, myContext).getFirst();
  if (input == null) return;
  final BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(toFile));
  try {
    FileUtil.copy(input, output);
  }
  finally {
    input.close();
    output.close();
  }
}
 
Example 3
Source File: TranslatingCompilerFilesMonitorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void savePathsToDelete(final File file, final Map<String, SourceUrlClassNamePair> outputs) {
  try {
    FileUtil.createParentDirs(file);
    final DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
    try {
      if (outputs != null) {
        os.writeInt(outputs.size());
        for (Map.Entry<String, SourceUrlClassNamePair> entry : outputs.entrySet()) {
          CompilerIOUtil.writeString(entry.getKey(), os);
          final SourceUrlClassNamePair pair = entry.getValue();
          CompilerIOUtil.writeString(pair.getSourceUrl(), os);
          CompilerIOUtil.writeString(pair.getClassName(), os);
        }
      }
      else {
        os.writeInt(0);
      }
    }
    finally {
      os.close();
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
Example 4
Source File: ArchiveVfsUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void extractEntry(ArchiveEntry entry, final InputStream inputStream, File outputDir, boolean overwrite) throws IOException {
  final boolean isDirectory = entry.isDirectory();
  final String relativeName = entry.getName();
  final File file = new File(outputDir, relativeName);
  if (file.exists() && !overwrite) return;

  FileUtil.createParentDirs(file);
  if (isDirectory) {
    file.mkdir();
  }
  else {
    final BufferedInputStream is = new BufferedInputStream(inputStream);
    final BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
    try {
      FileUtil.copy(is, os);
    }
    finally {
      os.close();
      is.close();
    }
  }
}
 
Example 5
Source File: IoFileBasedStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doSave(@Nullable Element element) throws IOException {
  if (myLineSeparator == null) {
    myLineSeparator = isUseLfLineSeparatorByDefault() ? LineSeparator.LF : LineSeparator.getSystemLineSeparator();
  }

  byte[] content = element == null ? null : StorageUtil.writeToBytes(element, myLineSeparator.getSeparatorString());
  try {
    if (myStreamProvider != null && myStreamProvider.isEnabled()) {
      // stream provider always use LF separator
      saveForProvider(myLineSeparator == LineSeparator.LF ? content : null, element);
    }
  }
  catch (Throwable e) {
    LOG.error(e);
  }

  if (content == null) {
    StorageUtil.deleteFile(myFile);
  }
  else {
    FileUtil.createParentDirs(myFile);

    StorageUtil.writeFile(myFile, content, isUseXmlProlog() ? myLineSeparator : null);
  }
}
 
Example 6
Source File: ZipUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void extractEntry(ZipEntry entry, final InputStream inputStream, File outputDir, boolean overwrite) throws IOException {
  final boolean isDirectory = entry.isDirectory();
  final String relativeName = entry.getName();
  final File file = new File(outputDir, relativeName);
  file.setLastModified(entry.getTime());
  if (file.exists() && !overwrite) return;

  FileUtil.createParentDirs(file);
  if (isDirectory) {
    file.mkdir();
  }
  else {
    final BufferedInputStream is = new BufferedInputStream(inputStream);
    final BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
    try {
      FileUtil.copy(is, os);
    }
    finally {
      os.close();
      is.close();
    }
  }
}
 
Example 7
Source File: VfsFileBasedStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSave(@Nullable Element element) throws IOException {
  if (myLineSeparator == null) {
    myLineSeparator = isUseLfLineSeparatorByDefault() ? LineSeparator.LF : LineSeparator.getSystemLineSeparator();
  }

  byte[] content = element == null ? null : StorageUtil.writeToBytes(element, myLineSeparator.getSeparatorString());
  try {
    if (myStreamProvider != null && myStreamProvider.isEnabled()) {
      // stream provider always use LF separator
      saveForProvider(myLineSeparator == LineSeparator.LF ? content : null, element);
    }
  }
  catch (Throwable e) {
    LOG.error(e);
  }

  if (content == null) {
    StorageUtil.deleteFile(myFile, this, getVirtualFile());
    myCachedVirtualFile = null;
  }
  else {
    VirtualFile file = getVirtualFile();
    if (file == null || !file.exists()) {
      FileUtil.createParentDirs(myFile);
      file = null;
    }
    myCachedVirtualFile = StorageUtil.writeFile(myFile, this, file, content, isUseXmlProlog() ? myLineSeparator : null);
  }
}
 
Example 8
Source File: DownloadUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void downloadContentToFile(@Nullable ProgressIndicator progress,
                                         @Nonnull String url,
                                         @Nonnull File outputFile) throws IOException {
  boolean parentDirExists = FileUtil.createParentDirs(outputFile);
  if (!parentDirExists) {
    throw new IOException("Parent dir of '" + outputFile.getAbsolutePath() + "' can not be created!");
  }
  OutputStream out = new FileOutputStream(outputFile);
  try {
    download(progress, url, out);
  } finally {
    out.close();
  }
}
 
Example 9
Source File: ArchivesBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> void buildArchive(final ArchivePackageInfo archive) throws IOException {
  if (archive.getPackedFiles().isEmpty() && archive.getPackedArchives().isEmpty()) {
    myContext.addMessage(CompilerMessageCategory.WARNING, "Archive '" + archive.getPresentableDestination() + "' has no files so it won't be created", null,
                         -1, -1);
    return;
  }

  myContext.getProgressIndicator().setText(CompilerBundle.message("packaging.compiler.message.building.0", archive.getPresentableDestination()));
  File tempFile = File.createTempFile("artifactCompiler", "tmp");

  myBuiltArchives.put(archive, tempFile);

  FileUtil.createParentDirs(tempFile);

  ArchivePackageWriter<T> packageWriter = (ArchivePackageWriter<T>)archive.getPackageWriter();

  T archiveFile;

  if (packageWriter instanceof ArchivePackageWriterEx) {
    archiveFile = ((ArchivePackageWriterEx<T>)packageWriter).createArchiveObject(tempFile, archive);
  }
  else {
    archiveFile = packageWriter.createArchiveObject(tempFile);
  }

  try {
    final THashSet<String> writtenPaths = new THashSet<>();
    for (Pair<String, VirtualFile> pair : archive.getPackedFiles()) {
      final VirtualFile sourceFile = pair.getSecond();
      if (sourceFile.isInLocalFileSystem()) {
        File file = VfsUtil.virtualToIoFile(sourceFile);
        addFileToArchive(archiveFile, packageWriter, file, pair.getFirst(), writtenPaths);
      }
      else {
        extractFileAndAddToArchive(archiveFile, packageWriter, sourceFile, pair.getFirst(), writtenPaths);
      }
    }

    for (Pair<String, ArchivePackageInfo> nestedArchive : archive.getPackedArchives()) {
      File nestedArchiveFile = myBuiltArchives.get(nestedArchive.getSecond());
      if (nestedArchiveFile != null) {
        addFileToArchive(archiveFile, packageWriter, nestedArchiveFile, nestedArchive.getFirst(), writtenPaths);
      }
      else {
        LOGGER.debug("nested archive file " + nestedArchive.getFirst() + " for " + archive.getPresentableDestination() + " not found");
      }
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
  finally {
    packageWriter.close(archiveFile);
  }
}
 
Example 10
Source File: ExternalStorageQueue.java    From consulo with Apache License 2.0 4 votes vote down vote up
private File writeLocalFile(@Nonnull File proxyDirectory, @Nonnull String fileSpec, RoamingType roamingType, byte[] compressedData) throws IOException {
  File file = new File(proxyDirectory, ExternalStorage.buildFileSpec(roamingType, fileSpec));
  FileUtil.createParentDirs(file);
  FileUtil.writeToFile(file, compressedData);
  return file;
}