Package com.actelion.research.util
Class IO
- java.lang.Object
-
- com.actelion.research.util.IO
-
public class IO extends java.lang.Object
IO 2003 MvK: Start implementation
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SEP
-
Constructor Summary
Constructors Constructor Description IO()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
canWriteAndDeleteInPath(java.io.File dir)
static java.lang.String
getBaseName(java.io.File file)
static java.lang.String
getBaseName(java.lang.String str)
static java.io.BufferedReader
getBufferedReader(java.lang.String sAbsolutePathIn)
Do not forget to close BufferedReaderstatic java.io.BufferedWriter
getBuffWrite(java.lang.String sAbsolutePathOut, boolean bAppend)
static java.lang.String
getExtension(java.io.File file)
static java.lang.String
getNextFileName(java.lang.String totalpath)
Has to be the total path of the file or there will be errors.static java.io.File
getUniqueDateDir(java.io.File dirParent)
static java.io.File
getUniqueDateDir(java.io.File dirParent, java.lang.String appendix)
static java.io.File
getUniqueDateDir(java.lang.String appendix)
static java.io.File
getUniqueDir(java.io.File dirParent, java.lang.String suffix)
static java.io.File
getUniqueFileName(java.io.File fiIn)
static java.io.File
getUniqueFileName(java.io.File file, java.io.File dirDestination)
static java.io.File
getUniqueFileName(java.io.File file, java.io.File dirDestination, java.text.DecimalFormat df)
If the file does not exists the input file is returned.static java.lang.String
getUniqueFileName(java.lang.String totalpath)
A number is added to the base name of the filestatic java.io.File
getUniqueFileName(java.lang.String sFilename, java.lang.String sDirDestination)
static java.io.File
getUniqueUserDir()
static void
mkdirs(java.io.File dir)
static void
mkdirs(java.lang.String path)
static java.lang.String
next(java.lang.String txt)
static java.lang.String
next(java.lang.String txt, java.text.DecimalFormat dfExtern)
static java.lang.String
read(java.io.File file)
static java.lang.String
read(java.io.InputStream is)
static void
readBetweenTags(java.lang.String sAbsolutePathIn, java.lang.String sTagStartRegEx, java.lang.String sTagEndRegEx, java.util.Vector<java.lang.String> vecStringContent)
static void
readFromTag(java.lang.String sAbsolutePathIn, java.lang.String sTagRegEx, java.util.Vector<java.lang.String> vecStringContent)
Reads all lines after a given tag and stores the lines as Strings in a vector object.static java.lang.String
readLine(java.io.InputStream is)
static java.lang.String
readLine(java.io.Reader is)
static java.lang.String
readLine(java.nio.channels.FileChannel fc)
static double[]
readLines2DoubleArray(java.io.File fiIntLineWise)
static int[]
readLines2IntArray(java.io.File fiIntLineWise)
Reads a file that contains one int per line.static java.util.List<java.lang.String>
readLines2List(java.io.File file)
static java.util.List<java.lang.String>
readLines2List(java.io.InputStream is)
The stream is not closed.static java.util.List<java.lang.String>
readLines2List(java.util.List<java.io.File> liFile)
static java.util.List<java.lang.Integer>
readListIntger(java.io.File fiTxt)
static void
skipUntilLineMatchesRegEx(java.io.InputStream in, java.lang.String regex)
static void
write(java.io.File file, double[] arr)
static void
write(java.io.File file, int[] arr)
static void
write(java.io.File file, java.lang.String sContent)
static void
write(java.io.File file, java.lang.String sContent, boolean bAppend)
static void
write(java.io.File file, java.util.List<java.lang.String> li)
Writes each string in a separate linestatic void
write(java.lang.String sAbsolutePathOut, java.lang.String sContent)
static void
write(java.lang.String sAbsolutePathOut, java.lang.String sContent, boolean bAppend)
void
write2Channel(java.nio.channels.FileChannel fc, java.lang.String str)
static void
writeIntegerList(java.io.File file, java.util.List<java.lang.Integer> li)
-
-
-
Method Detail
-
canWriteAndDeleteInPath
public static boolean canWriteAndDeleteInPath(java.io.File dir) throws java.io.IOException
- Throws:
java.io.IOException
-
getBufferedReader
public static java.io.BufferedReader getBufferedReader(java.lang.String sAbsolutePathIn) throws java.io.FileNotFoundException
Do not forget to close BufferedReader- Parameters:
sAbsolutePathIn
- path- Returns:
- BufferedReader
- Throws:
java.io.FileNotFoundException
-
getUniqueFileName
public static java.lang.String getUniqueFileName(java.lang.String totalpath)
A number is added to the base name of the file- Parameters:
totalpath
-- Returns:
-
getUniqueFileName
public static java.io.File getUniqueFileName(java.io.File fiIn)
-
getUniqueFileName
public static java.io.File getUniqueFileName(java.lang.String sFilename, java.lang.String sDirDestination)
-
getUniqueFileName
public static java.io.File getUniqueFileName(java.io.File file, java.io.File dirDestination)
-
getUniqueFileName
public static java.io.File getUniqueFileName(java.io.File file, java.io.File dirDestination, java.text.DecimalFormat df)
If the file does not exists the input file is returned.- Parameters:
file
-dirDestination
-df
-- Returns:
-
getUniqueUserDir
public static java.io.File getUniqueUserDir() throws java.io.IOException
- Throws:
java.io.IOException
-
getUniqueDateDir
public static java.io.File getUniqueDateDir(java.io.File dirParent) throws java.io.IOException
- Throws:
java.io.IOException
-
getUniqueDateDir
public static java.io.File getUniqueDateDir(java.lang.String appendix) throws java.io.IOException
- Throws:
java.io.IOException
-
getUniqueDateDir
public static java.io.File getUniqueDateDir(java.io.File dirParent, java.lang.String appendix) throws java.io.IOException
- Throws:
java.io.IOException
-
getUniqueDir
public static java.io.File getUniqueDir(java.io.File dirParent, java.lang.String suffix) throws java.io.IOException
- Throws:
java.io.IOException
-
getNextFileName
public static java.lang.String getNextFileName(java.lang.String totalpath)
Has to be the total path of the file or there will be errors.- Parameters:
totalpath
-- Returns:
-
next
public static java.lang.String next(java.lang.String txt)
-
next
public static java.lang.String next(java.lang.String txt, java.text.DecimalFormat dfExtern)
- Parameters:
txt
- String with an integer num at the end. (blabla567)- Returns:
- Adds one to the last number (blabla568). If no number in text 001 is added.
-
getBuffWrite
public static java.io.BufferedWriter getBuffWrite(java.lang.String sAbsolutePathOut, boolean bAppend) throws java.io.IOException
- Throws:
java.io.IOException
-
getBaseName
public static java.lang.String getBaseName(java.lang.String str)
- Parameters:
str
-- Returns:
- base name without extension.
-
getBaseName
public static java.lang.String getBaseName(java.io.File file)
-
getExtension
public static java.lang.String getExtension(java.io.File file)
- Parameters:
file
-- Returns:
- the part after the the last '.' inclusive the '.'. Returns String with length null when no extension found.
-
mkdirs
public static void mkdirs(java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
mkdirs
public static void mkdirs(java.io.File dir) throws java.io.IOException
- Throws:
java.io.IOException
-
readBetweenTags
public static void readBetweenTags(java.lang.String sAbsolutePathIn, java.lang.String sTagStartRegEx, java.lang.String sTagEndRegEx, java.util.Vector<java.lang.String> vecStringContent)
-
readFromTag
public static void readFromTag(java.lang.String sAbsolutePathIn, java.lang.String sTagRegEx, java.util.Vector<java.lang.String> vecStringContent)
Reads all lines after a given tag and stores the lines as Strings in a vector object.- Parameters:
sAbsolutePathIn
- path of the input filesTagRegEx
- the tag as regular expressionvecStringContent
- contains the result of the read in.
-
skipUntilLineMatchesRegEx
public static void skipUntilLineMatchesRegEx(java.io.InputStream in, java.lang.String regex) throws java.lang.Exception
- Throws:
java.lang.Exception
-
read
public static java.lang.String read(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
readListIntger
public static java.util.List<java.lang.Integer> readListIntger(java.io.File fiTxt) throws java.io.IOException
- Throws:
java.io.IOException
-
readLines2IntArray
public static int[] readLines2IntArray(java.io.File fiIntLineWise) throws java.io.IOException
Reads a file that contains one int per line.- Parameters:
fiIntLineWise
-- Returns:
- Throws:
java.io.IOException
-
readLines2DoubleArray
public static double[] readLines2DoubleArray(java.io.File fiIntLineWise) throws java.io.IOException
- Throws:
java.io.IOException
-
readLine
public static java.lang.String readLine(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public static java.lang.String read(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
readLine
public static java.lang.String readLine(java.io.Reader is) throws java.io.IOException
- Throws:
java.io.IOException
-
readLine
public static java.lang.String readLine(java.nio.channels.FileChannel fc) throws java.io.IOException
- Throws:
java.io.IOException
-
readLines2List
public static java.util.List<java.lang.String> readLines2List(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
readLines2List
public static java.util.List<java.lang.String> readLines2List(java.io.InputStream is) throws java.io.IOException
The stream is not closed.- Parameters:
is
-- Returns:
- Throws:
java.io.IOException
-
readLines2List
public static java.util.List<java.lang.String> readLines2List(java.util.List<java.io.File> liFile) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public static void write(java.lang.String sAbsolutePathOut, java.lang.String sContent)
-
write
public static void write(java.lang.String sAbsolutePathOut, java.lang.String sContent, boolean bAppend)
-
write
public static void write(java.io.File file, java.lang.String sContent)
-
write
public static void write(java.io.File file, java.lang.String sContent, boolean bAppend)
-
write2Channel
public void write2Channel(java.nio.channels.FileChannel fc, java.lang.String str) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public static void write(java.io.File file, java.util.List<java.lang.String> li) throws java.io.IOException
Writes each string in a separate line- Parameters:
file
-li
-- Throws:
java.io.IOException
-
writeIntegerList
public static void writeIntegerList(java.io.File file, java.util.List<java.lang.Integer> li) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public static void write(java.io.File file, int[] arr) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public static void write(java.io.File file, double[] arr) throws java.io.IOException
- Throws:
java.io.IOException
-
-