// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.model;

import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

abstract class BranchedVirtualFile extends LightVirtualFile {
  @NotNull final VirtualFile original;
  @NotNull final ModelBranch branch;

  BranchedVirtualFile(@NotNull VirtualFile original, @NotNull ModelBranch branch) {
    super(original.getName(), original.getFileType(), "", original.getModificationStamp());
    this.original = original;
    this.branch = branch;
  }

  @Override
  public @NotNull OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
    throw new UnsupportedOperationException("Branch files shouldn't be modified");
  }

  @Override
  public void setContent(Object requestor, @NotNull CharSequence content, boolean fireEvent) {
    throw new UnsupportedOperationException("Branch files shouldn't be modified");
  }

  @Override
  public boolean isDirectory() {
    return original.isDirectory();
  }

  @Override
  public InputStream getInputStream() throws IOException {
    return new ByteArrayInputStream(contentsToByteArray());
  }

  @Override
  public VirtualFile getParent() {
    VirtualFile parent = original.getParent();
    return parent == null ? null : branch.findFileCopy(parent);
  }

  @Override
  public VirtualFile[] getChildren() {
    VirtualFile[] children = original.getChildren();
    return children == null ? null : ContainerUtil.map2Array(children, VirtualFile.class, f -> branch.findFileCopy(f));
  }

}
@@ -373,84 +373,19 @@
 .io.
-ByteArrayInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream
+IOException
 ;%0Aim
@@ -1304,144 +1304,8 @@
  %7D%0A%0A
-  @Override%0A  public InputStream getInputStream() throws IOException %7B%0A    return new ByteArrayInputStream(contentsToByteArray());%0A  %7D%0A%0A
   @O

simplify BranchedVirtualFile (IDEA-CR-65317)