KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > io > FileBusyException


1 /*
2  * FileBusyException.java
3  *
4  * Created on 11. September 2005, 18:10
5  */

6 /*
7  * Copyright 2005 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.io;
23
24 import de.schlichtherle.io.archive.Archive;
25 import de.schlichtherle.io.archive.spi.InputArchiveBusyException;
26 import de.schlichtherle.io.archive.spi.OutputArchiveBusyException;
27
28 import java.io.FileNotFoundException JavaDoc;
29
30 /**
31  * This exception is thrown by the constructors of either the class
32  * {@link FileInputStream} or {@link FileOutputStream} or those copy methods
33  * of the {@link File} class which throw an <code>IOException</code> to
34  * indicate that an archive entry cannot get accessed because the client
35  * application is trying to input or output to the same archive file
36  * simultaneously and the respective archive driver does not support this
37  * or the archive file needs an automatic update which cannot get performed
38  * because the client is still using other open {@link FileInputStream}s or
39  * {@link FileOutputStream}s for other entries in the same archive file.
40  * <p>
41  * As a resolution to this (rather complex) issue, please make sure that you
42  * always close your streams using the following idiom:
43  * <p>
44  * <pre>
45  * FileOutputStream fos = new FileOutputStream(file);
46  * try {
47  * // access fos here
48  * }
49  * finally {
50  * fos.close();
51  * }
52  * </pre>
53  * <p>
54  * <b>Notes:</b>
55  * <ul>
56  * <li>This issue is not at all specific to TrueZIP: For example, if you use
57  * a <code>FileInputStream</code> or <code>FileOutputStream</code> on the
58  * Windows platform, certain file operations such as <code>delete()</code>
59  * and others will fail as long the stream hasn't been closed.
60  * <li>Archive entry streams are actually automatically closed if they get
61  * finalized, but you should never rely on the garbage collector to do
62  * your work.
63  * <li>You may call {@link File#update()} or {@link File#umount()} in order
64  * to force any archive entry streams to be closed and disconnected from
65  * the archive.
66  * A subsequent try to create an archive entry stream should succeed
67  * unless other exceptional conditions apply.
68  * However, if the client application is still using the disconnected
69  * streams, it will receive <code>IOExceptions</code> on other method
70  * than <code>close()</code>.
71  *
72  * @see FileInputStream
73  * @see FileOutputStream
74  * @see File#update()
75  * @see File#umount()
76  *
77  * @author Christian Schlichtherle
78  * @version @version@
79  */

80 public class FileBusyException extends FileNotFoundException JavaDoc {
81
82     /**
83      * For use by
84      * {@link de.schlichtherle.io.archive.spi.InputArchiveBusyException} and
85      * {@link de.schlichtherle.io.archive.spi.OutputArchiveBusyException} only.
86      */

87     protected FileBusyException() {
88     }
89
90     // TODO: Remove this.
91
/**
92      * @deprecated You should not use this constructor.
93      * It will vanish in the next major version.
94      */

95     public FileBusyException(InputArchiveBusyException cause) {
96         super(cause != null ? cause.getLocalizedMessage() : null);
97         initCause(cause);
98     }
99
100     // TODO: Remove this.
101
/**
102      * @deprecated You should not use this constructor.
103      * It will vanish in the next major version.
104      */

105     public FileBusyException(OutputArchiveBusyException cause) {
106         super(cause != null ? cause.getLocalizedMessage() : null);
107         initCause(cause);
108     }
109
110     public FileBusyException(ArchiveBusyException cause) {
111         super(cause != null ? cause.getLocalizedMessage() : null);
112         initCause(cause);
113     }
114 }
115
Popular Tags