190 throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e);
191 }
192 }
193
194 /**
195 * Open an writer for the file, using the encoding (if any) given in the
196 * doclet configuration.
197 * The file must have been created with a location of
198 * {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path.
199 *
200 * @throws DocFileIOException if there is a problem while opening stream
201 * @throws UnsupportedEncodingException if the configured encoding is not supported
202 */
203 @Override
204 public Writer openWriter() throws DocFileIOException, UnsupportedEncodingException {
205 if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT)
206 throw new IllegalStateException();
207
208 try {
209 OutputStream out = getFileObjectForOutput(path).openOutputStream();
210 return new BufferedWriter(new OutputStreamWriter(out, configuration.docencoding));
211 } catch (IOException e) {
212 throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e);
213 }
214 }
215
216 /** Return true if the file can be read. */
217 @Override
218 public boolean canRead() {
219 return Files.isReadable(file);
220 }
221
222 /** Return true if the file can be written. */
223 @Override
224 public boolean canWrite() {
225 return Files.isWritable(file);
226 }
227
228 /** Return true if the file exists. */
229 @Override
230 public boolean exists() {
311 }
312
313 /**
314 * Derive a new file by resolving a relative path against this file.
315 * The new file will inherit the configuration and location of this file
316 * If this file has a path set, the new file will have a corresponding
317 * new path.
318 */
319 @Override
320 public DocFile resolve(String p) {
321 if (location == null && path == null) {
322 return new StandardDocFile(file.resolve(p));
323 } else {
324 return new StandardDocFile(location, path.resolve(p));
325 }
326 }
327
328 /**
329 * Resolve a relative file against the given output location.
330 * @param locn Currently, only
331 * {@link DocumentationTool.Location.DOCUMENTATION_OUTPUT} is supported.
332 */
333 @Override
334 public DocFile resolveAgainst(Location locn) {
335 if (locn != DocumentationTool.Location.DOCUMENTATION_OUTPUT)
336 throw new IllegalArgumentException();
337 return new StandardDocFile(getDestDir().resolve(file));
338 }
339
340 /** Return a string to identify the contents of this object,
341 * for debugging purposes.
342 */
343 @Override
344 public String toString() {
345 StringBuilder sb = new StringBuilder();
346 sb.append("StandardDocFile[");
347 if (location != null)
348 sb.append("locn:").append(location).append(",");
349 if (path != null)
350 sb.append("path:").append(path.getPath()).append(",");
351 sb.append("file:").append(file);
|
190 throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e);
191 }
192 }
193
194 /**
195 * Open an writer for the file, using the encoding (if any) given in the
196 * doclet configuration.
197 * The file must have been created with a location of
198 * {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} and a corresponding relative path.
199 *
200 * @throws DocFileIOException if there is a problem while opening stream
201 * @throws UnsupportedEncodingException if the configured encoding is not supported
202 */
203 @Override
204 public Writer openWriter() throws DocFileIOException, UnsupportedEncodingException {
205 if (location != DocumentationTool.Location.DOCUMENTATION_OUTPUT)
206 throw new IllegalStateException();
207
208 try {
209 OutputStream out = getFileObjectForOutput(path).openOutputStream();
210 String docencoding = configuration.getOptions().docEncoding;
211 return new BufferedWriter(new OutputStreamWriter(out, docencoding));
212 } catch (IOException e) {
213 throw new DocFileIOException(this, DocFileIOException.Mode.WRITE, e);
214 }
215 }
216
217 /** Return true if the file can be read. */
218 @Override
219 public boolean canRead() {
220 return Files.isReadable(file);
221 }
222
223 /** Return true if the file can be written. */
224 @Override
225 public boolean canWrite() {
226 return Files.isWritable(file);
227 }
228
229 /** Return true if the file exists. */
230 @Override
231 public boolean exists() {
312 }
313
314 /**
315 * Derive a new file by resolving a relative path against this file.
316 * The new file will inherit the configuration and location of this file
317 * If this file has a path set, the new file will have a corresponding
318 * new path.
319 */
320 @Override
321 public DocFile resolve(String p) {
322 if (location == null && path == null) {
323 return new StandardDocFile(file.resolve(p));
324 } else {
325 return new StandardDocFile(location, path.resolve(p));
326 }
327 }
328
329 /**
330 * Resolve a relative file against the given output location.
331 * @param locn Currently, only
332 * {@link DocumentationTool.Location#DOCUMENTATION_OUTPUT} is supported.
333 */
334 @Override
335 public DocFile resolveAgainst(Location locn) {
336 if (locn != DocumentationTool.Location.DOCUMENTATION_OUTPUT)
337 throw new IllegalArgumentException();
338 return new StandardDocFile(getDestDir().resolve(file));
339 }
340
341 /** Return a string to identify the contents of this object,
342 * for debugging purposes.
343 */
344 @Override
345 public String toString() {
346 StringBuilder sb = new StringBuilder();
347 sb.append("StandardDocFile[");
348 if (location != null)
349 sb.append("locn:").append(location).append(",");
350 if (path != null)
351 sb.append("path:").append(path.getPath()).append(",");
352 sb.append("file:").append(file);
|