do not use VFS to read .class file content,
[fedora-idea.git] / java / compiler / impl / src / com / intellij / compiler / impl / javaCompiler / FileObject.java
blobe9483bcaa98dd0aeac2ccd7127ed2a7c0d740584
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.compiler.impl.javaCompiler;
18 import com.intellij.openapi.util.io.FileUtil;
19 import org.jetbrains.annotations.NotNull;
21 import java.io.File;
22 import java.io.FileNotFoundException;
23 import java.io.IOException;
25 /**
26 * @author cdr
28 public class FileObject {
29 private static final byte[] NOT_LOADED = new byte[0];
31 private final File myFile;
32 private final byte[] myContent;
34 public FileObject(@NotNull File file, @NotNull byte[] content) {
35 myFile = file;
36 myContent = content;
39 public FileObject(File file) {
40 myFile = file;
41 myContent = NOT_LOADED;
44 public File getFile() {
45 return myFile;
48 public byte[] getContent() throws IOException {
49 if (myContent == NOT_LOADED) {
50 return FileUtil.loadFileBytes(myFile);
52 return myContent;
55 public void save() throws IOException {
56 if (myContent == NOT_LOADED) {
57 return; // already on disk
59 try {
60 FileUtil.writeToFile(myFile, myContent);
62 catch (FileNotFoundException e) {
63 FileUtil.createParentDirs(myFile);
64 FileUtil.writeToFile(myFile, myContent);
68 @Override
69 public String toString() {
70 return getFile().toString();