Package eu.bandm.tools.util.files
Class StreamsReadersWriters
java.lang.Object
eu.bandm.tools.util.files.StreamsReadersWriters
Utility class of static methods for frequently needed operations on
stream/reades/writers etc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Converts all characters read to lower or to upper. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Copy the contents of one file verbatim (on the level of byte io) into the other.static void
copyReaderWriter
(Reader in, Writer out) Copy the contents of the Reader verbatim (on the level of character io) into the writer.static void
copyStreams
(InputStream in, OutputStream out) Copy the contents of one stream verbatim (on the level of byte io) into the other.static void
copyToDocFiles
(String outputRootDir, String packageName, String filename) Copies an input file to a source text generator tool into thedoc-files
sub-directory of the output dir, into which the sources are generated.static String
readTextFileIntoString
(File input) Read the character contents of the given file into one (large) String value.static String
readTextFileIntoString
(InputStream stream) Read the character contents of the given stream into one (large) String value.static String
readTextFileIntoString
(Reader reader) Read the character contents of the character reader into one (large) String value.Copy the contents of the Reader verbatim (on the level of character io) into the writer, with the replacement of one given String by another.Copy the contents of the Reader verbatim (on the level of character io) into the writer, with the replacement of one given String by another.static void
writeStringToTextFile
(String text, File file) Write the string into some open file.
-
Method Details
-
copyFiles
Copy the contents of one file verbatim (on the level of byte io) into the other.- Parameters:
in
- file to read fromout
- file to write to- Throws:
IOException
- if reading or writing the files does
-
copyStreams
Copy the contents of one stream verbatim (on the level of byte io) into the other. Opening and closing of both Streams is left to the caller.- Parameters:
in
- stream to read fromout
- stream to write to- Throws:
IOException
- if reading or writing the streams does
-
copyReaderWriter
Copy the contents of the Reader verbatim (on the level of character io) into the writer. Opening and closing of Reader and Writer is left to the caller.- Parameters:
in
- reader to read fromout
- writer to write to- Throws:
IOException
- if the peer reader or writer does
-
replace
public static SortedSet<Integer> replace(Reader in, Writer out, String from, String to) throws IOException Copy the contents of the Reader verbatim (on the level of character io) into the writer, with the replacement of one given String by another. The caller is responsible for closing, esp. of the Writer. The line terminator written is '\\n'.- Parameters:
in
- reader to read fromout
- writer to write tofrom
- the string to replaceto
- the replacement- Returns:
- the line numbers (1-based) in which at least one replacement has been executed.
- Throws:
IOException
- if the peer reader or writer does- See Also:
-
replace
public static SortedSet<Integer> replace(Reader in, Writer out, String from, String to, String eoLine) throws IOException Copy the contents of the Reader verbatim (on the level of character io) into the writer, with the replacement of one given String by another. The replacement is carried out line by line by {String#replace(CharSequence,CharSequence)}, which means mutiple non-overlapping replacements. The caller is responsible for closing, esp. of the Writer. The line terminator written is '\\n'.- Parameters:
in
- reader to read fromout
- writer to write tofrom
- the string to replaceto
- the replacementeoLine
- the line termination character sequence written to the output.- Returns:
- the line numbers (1-based) in which at least one replacement has been executed.
- Throws:
IOException
- if the peer reader or writer does
-
readTextFileIntoString
Read the character contents of the given file into one (large) String value. Assumes that the file is encoded inStandardCharsets.UTF_8
.- Parameters:
input
- the file to read- Returns:
- the file contents as a string
- Throws:
IOException
- if the file reader does
-
readTextFileIntoString
Read the character contents of the given stream into one (large) String value. Assumes that the file is encoded inStandardCharsets.UTF_8
.- Parameters:
stream
- is the input to read- Returns:
- the stream contents as a string
- Throws:
IOException
- if the input stream does
-
readTextFileIntoString
Read the character contents of the character reader into one (large) String value.- Parameters:
reader
- to read- Returns:
- the reader contents as a string
- Throws:
IOException
- if the reader does
-
writeStringToTextFile
Write the string into some open file. Do so encoded inStandardCharsets.UTF_8
.- Parameters:
text
- the string to writefile
- to writ into- Throws:
IOException
- if the file writer does
-
copyToDocFiles
public static void copyToDocFiles(String outputRootDir, String packageName, String filename) throws IOException Copies an input file to a source text generator tool into thedoc-files
sub-directory of the output dir, into which the sources are generated.- Parameters:
outputRootDir
- the directory into which all generated sources are stored by the tool, in sub-directories indicated by a non-empty package name.packageName
- the name of the generated package, indicates the sub-directory below outputRootDir.filename
- the name of the file to copy. The local part of the file is kept, the file system position is given by the concatenation of outputRootDir, packageName. and the constant"doc-files"
.- Throws:
IOException
- if the input or output agents do
-