Package io.micronaut.inject.writer
Interface GeneratedFile
public interface GeneratedFile
A common interface to allow referencing a generated file in either Groovy or Java.
- Since:
- 1.0
- Author:
- graemerocher
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
A consumer which may throw an IOException. -
Method Summary
Modifier and TypeMethodDescriptiongetName()
Gets the character content of this file object, if available.Gets an InputStream for this file object.Gets an OutputStream for this file object.Gets a reader for this object.Gets a Writer for this file object.toURI()
The URI to write to.default void
write
(GeneratedFile.ThrowingConsumer<? super Writer> consumer) Writes the context to the file.
-
Method Details
-
toURI
URI toURI()The URI to write to.- Returns:
- The URI
-
getName
String getName()- Returns:
- The name of the file
-
openInputStream
Gets an InputStream for this file object.- Returns:
- an InputStream
- Throws:
IllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support byte accessIOException
- if an I/O error occurred
-
openOutputStream
Gets an OutputStream for this file object.- Returns:
- an OutputStream
- Throws:
IllegalStateException
- if this file object was opened for reading and does not support writingUnsupportedOperationException
- if this kind of file object does not support byte accessIOException
- if an I/O error occurred
-
openReader
Gets a reader for this object. The returned reader will replace bytes that cannot be decoded with the default translation character. In addition, the reader may report a diagnostic unlessignoreEncodingErrors
is true.- Returns:
- a Reader
- Throws:
IllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurred
-
getTextContent
Gets the character content of this file object, if available. Any byte that cannot be decoded will be replaced by the default translation character. In addition, a diagnostic may be reported unlessignoreEncodingErrors
is true.- Returns:
- a CharSequence if available;
null
otherwise - Throws:
IllegalStateException
- if this file object was opened for writing and does not support readingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurred
-
openWriter
Gets a Writer for this file object.- Returns:
- a Writer
- Throws:
IllegalStateException
- if this file object was opened for reading and does not support writingUnsupportedOperationException
- if this kind of file object does not support character accessIOException
- if an I/O error occurred
-
write
Writes the context to the file.- Parameters:
consumer
- the code generating block- Throws:
IOException
- in case of I/O error- Since:
- 4.2.0
-