|
| 1 | +/* |
| 2 | + * Copyright 2018 Mr Duy |
| 3 | + * |
| 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 |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 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. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.duy.ccppcompiler.compiler.diagnostic; |
| 18 | + |
| 19 | +import android.net.Uri; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | +import java.io.InputStream; |
| 23 | +import java.io.OutputStream; |
| 24 | +import java.io.Reader; |
| 25 | +import java.io.Writer; |
| 26 | + |
| 27 | +/** |
| 28 | + * File abstraction for tools. In this context, <em>file</em> means |
| 29 | + * an abstraction of regular files and other sources of data. For |
| 30 | + * example, a file object can be used to represent regular files, |
| 31 | + * memory cache, or data in databases. |
| 32 | + * <p> |
| 33 | + * <p>All methods in this interface might throw a SecurityException if |
| 34 | + * a security exception occurs. |
| 35 | + * <p> |
| 36 | + * <p>Unless explicitly allowed, all methods in this interface might |
| 37 | + * throw a NullPointerException if given a {@code null} argument. |
| 38 | + */ |
| 39 | +public interface FileObject { |
| 40 | + |
| 41 | + /** |
| 42 | + * Returns a URI identifying this file object. |
| 43 | + * |
| 44 | + * @return a URI |
| 45 | + */ |
| 46 | + Uri toUri(); |
| 47 | + |
| 48 | + /** |
| 49 | + * Gets a user-friendly name for this file object. The exact |
| 50 | + * value returned is not specified but implementations should take |
| 51 | + * care to preserve names as given by the user. For example, if |
| 52 | + * the user writes the filename {@code "BobsApp\Test.java"} on |
| 53 | + * the command line, this method should return {@code |
| 54 | + * "BobsApp\Test.java"} whereas the {@linkplain #toUri toUri} |
| 55 | + * method might return {@code |
| 56 | + * file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java}. |
| 57 | + * |
| 58 | + * @return a user-friendly name |
| 59 | + */ |
| 60 | + String getName(); |
| 61 | + |
| 62 | + /** |
| 63 | + * Gets an InputStream for this file object. |
| 64 | + * |
| 65 | + * @return an InputStream |
| 66 | + * @throws IllegalStateException if this file object was |
| 67 | + * opened for writing and does not support reading |
| 68 | + * @throws UnsupportedOperationException if this kind of file |
| 69 | + * object does not support byte access |
| 70 | + * @throws IOException if an I/O error occurred |
| 71 | + */ |
| 72 | + InputStream openInputStream() throws IOException; |
| 73 | + |
| 74 | + /** |
| 75 | + * Gets an OutputStream for this file object. |
| 76 | + * |
| 77 | + * @return an OutputStream |
| 78 | + * @throws IllegalStateException if this file object was |
| 79 | + * opened for reading and does not support writing |
| 80 | + * @throws UnsupportedOperationException if this kind of |
| 81 | + * file object does not support byte access |
| 82 | + * @throws IOException if an I/O error occurred |
| 83 | + */ |
| 84 | + OutputStream openOutputStream() throws IOException; |
| 85 | + |
| 86 | + /** |
| 87 | + * Gets a reader for this object. The returned reader will |
| 88 | + * replace bytes that cannot be decoded with the default |
| 89 | + * translation character. In addition, the reader may report a |
| 90 | + * diagnostic unless {@code ignoreEncodingErrors} is true. |
| 91 | + * |
| 92 | + * @param ignoreEncodingErrors ignore encoding errors if true |
| 93 | + * @return a Reader |
| 94 | + * @throws IllegalStateException if this file object was |
| 95 | + * opened for writing and does not support reading |
| 96 | + * @throws UnsupportedOperationException if this kind of |
| 97 | + * file object does not support character access |
| 98 | + * @throws IOException if an I/O error occurred |
| 99 | + */ |
| 100 | + Reader openReader(boolean ignoreEncodingErrors) throws IOException; |
| 101 | + |
| 102 | + /** |
| 103 | + * Gets the character content of this file object, if available. |
| 104 | + * Any byte that cannot be decoded will be replaced by the default |
| 105 | + * translation character. In addition, a diagnostic may be |
| 106 | + * reported unless {@code ignoreEncodingErrors} is true. |
| 107 | + * |
| 108 | + * @param ignoreEncodingErrors ignore encoding errors if true |
| 109 | + * @return a CharSequence if available; {@code null} otherwise |
| 110 | + * @throws IllegalStateException if this file object was |
| 111 | + * opened for writing and does not support reading |
| 112 | + * @throws UnsupportedOperationException if this kind of |
| 113 | + * file object does not support character access |
| 114 | + * @throws IOException if an I/O error occurred |
| 115 | + */ |
| 116 | + CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException; |
| 117 | + |
| 118 | + /** |
| 119 | + * Gets a Writer for this file object. |
| 120 | + * |
| 121 | + * @return a Writer |
| 122 | + * @throws IllegalStateException if this file object was |
| 123 | + * opened for reading and does not support writing |
| 124 | + * @throws UnsupportedOperationException if this kind of |
| 125 | + * file object does not support character access |
| 126 | + * @throws IOException if an I/O error occurred |
| 127 | + */ |
| 128 | + Writer openWriter() throws IOException; |
| 129 | + |
| 130 | + /** |
| 131 | + * Gets the time this file object was last modified. The time is |
| 132 | + * measured in milliseconds since the epoch (00:00:00 GMT, January |
| 133 | + * 1, 1970). |
| 134 | + * |
| 135 | + * @return the time this file object was last modified; or 0 if |
| 136 | + * the file object does not exist, if an I/O error occurred, or if |
| 137 | + * the operation is not supported |
| 138 | + */ |
| 139 | + long getLastModified(); |
| 140 | + |
| 141 | + /** |
| 142 | + * Deletes this file object. In case of errors, returns false. |
| 143 | + * |
| 144 | + * @return true if and only if this file object is successfully |
| 145 | + * deleted; false otherwise |
| 146 | + */ |
| 147 | + boolean delete(); |
| 148 | + |
| 149 | +} |
0 commit comments