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
;
22 import java
.io
.FileNotFoundException
;
23 import java
.io
.IOException
;
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
) {
39 public FileObject(File file
) {
41 myContent
= NOT_LOADED
;
44 public File
getFile() {
48 public byte[] getContent() throws IOException
{
49 if (myContent
== NOT_LOADED
) {
50 return FileUtil
.loadFileBytes(myFile
);
55 public void save() throws IOException
{
56 if (myContent
== NOT_LOADED
) {
57 return; // already on disk
60 FileUtil
.writeToFile(myFile
, myContent
);
62 catch (FileNotFoundException e
) {
63 FileUtil
.createParentDirs(myFile
);
64 FileUtil
.writeToFile(myFile
, myContent
);
69 public String
toString() {
70 return getFile().toString();