示例#1
0
 @Override
 @NotNull
 public byte[] contentsToByteArray(int contentId) throws IOException {
   final DataInputStream stream = readContentById(contentId);
   assert stream != null : contentId;
   return FileUtil.loadBytes(stream);
 }
示例#2
0
 @NotNull
 private static String normalizeRootUrl(
     @NotNull String basePath, @NotNull NewVirtualFileSystem fs) {
   // need to protect against relative path of the form "/x/../y"
   return UriUtil.trimTrailingSlashes(
       fs.getProtocol()
           + URLUtil.SCHEME_SEPARATOR
           + VfsImplUtil.normalize(fs, FileUtil.toCanonicalPath(basePath)));
 }
示例#3
0
 private FsRoot(
     @NotNull NewVirtualFileSystem fs,
     int id,
     VfsData.Segment segment,
     VfsData.DirectoryData data,
     @NotNull String basePath) {
   super(id, segment, data, fs);
   myName = FileUtil.toSystemIndependentName(basePath);
 }
示例#4
0
  @Override
  @NotNull
  public byte[] contentsToByteArray(@NotNull final VirtualFile file, boolean cacheContent)
      throws IOException {
    InputStream contentStream = null;
    boolean reloadFromDelegate;
    boolean outdated;
    int fileId;
    synchronized (myInputLock) {
      fileId = getFileId(file);
      outdated = checkFlag(fileId, MUST_RELOAD_CONTENT) || FSRecords.getLength(fileId) == -1L;
      reloadFromDelegate = outdated || (contentStream = readContent(file)) == null;
    }

    if (reloadFromDelegate) {
      final NewVirtualFileSystem delegate = getDelegate(file);

      final byte[] content;
      if (outdated) {
        // in this case, file can have out-of-date length. so, update it first (it's needed for
        // correct contentsToByteArray() work)
        // see IDEA-90813 for possible bugs
        FSRecords.setLength(fileId, delegate.getLength(file));
        content = delegate.contentsToByteArray(file);
      } else {
        // a bit of optimization
        content = delegate.contentsToByteArray(file);
        FSRecords.setLength(fileId, content.length);
      }

      ApplicationEx application = (ApplicationEx) ApplicationManager.getApplication();
      // we should cache every local files content
      // because the local history feature is currently depends on this cache,
      // perforce offline mode as well
      if ((!delegate.isReadOnly()
              ||
              // do not cache archive content unless asked
              cacheContent && !application.isInternal() && !application.isUnitTestMode())
          && content.length <= PersistentFSConstants.FILE_LENGTH_TO_CACHE_THRESHOLD) {
        synchronized (myInputLock) {
          writeContent(file, new ByteSequence(content), delegate.isReadOnly());
          setFlag(file, MUST_RELOAD_CONTENT, false);
        }
      }

      return content;
    } else {
      try {
        final int length = (int) file.getLength();
        assert length >= 0 : file;
        return FileUtil.loadBytes(contentStream, length);
      } catch (IOException e) {
        throw FSRecords.handleError(e);
      }
    }
  }
 private FsRoot(@NotNull NewVirtualFileSystem fs, int rootId, @NotNull String basePath) {
   super(fs, rootId);
   myName = FileUtil.toSystemIndependentName(basePath);
 }