PSEK-Fitnesse-Fixtures  2.3.x (JDK11)
nl.psek.fitnesse.fixtures.general.util.FileUtils Class Reference

A fixture that can be used to generate a (temporary) file, write and read to files and copy files (including over SMB) More...

Classes

class  DirFilenameFilter
 Ik ben een FilenameFilter die op basis van een bestandsnaam pattern kan gebruikt worden. More...
 

Public Member Functions

 FileUtils ()
 Default constructor. More...
 
void copyFile (String sourceFile, String destinationFile)
 Copies a file from source to target. More...
 
void copyFileToSMBShare (String sourceFile, String destinationFile, String domain, String domainUsername, String domainPassword)
 Copy file to smb share. More...
 
void deleteFile (String filename)
 Delete een file als deze bestaat. More...
 
long getFileSize (String location)
 Gets file size. More...
 
boolean verifyFileExists (String location)
 Verifies that a file exists. More...
 
boolean verifySMBFileExists (String location, String domain, String domainUser, String domainPassword)
 Verify smb file exists boolean. More...
 

Static Public Member Functions

static boolean copyFileTo (File sourceFile, File destinationFile) throws IOException
 Ik kopieer een bestand van bron naar bestemming. More...
 
static String createBinaryTempFile (String filenamePrefix, String filenameSuffix, byte[] filecontents)
 Creates a temporary binary file. More...
 
static void createFile (File file) throws IOException
 Ik maak een nieuw bestand aan als deze nog niet bestaat. More...
 
static String createTempFile (String filenamePrefix, String filenameSuffix, String filecontents)
 Creates a temporary UTF-8 file. More...
 
static File file (String filename)
 File file. More...
 
static List< File > fileSearch (File directory, boolean deepSearch, FileEvaluator fileEvaluator, FilenameFilter filter) throws IOException
 Ik stel een array van. More...
 
static List< File > fileSearch (File[] fileArray, FileEvaluator fileEvaluator) throws IOException
 Ik zoek een. More...
 
static List< File > filesInFolder (File dir, String regexFilePattern) throws IOException
 Files in folder list. More...
 
static List< File > filesInFolder (String directory, String regexFilePattern) throws IOException
 Files in folder list. More...
 
static int getDatePart (Date date, int calendarPart)
 Gets date part. More...
 
static String readFile (final String fileName, final String encoding) throws IOException
 Read file string. More...
 
static List< String > readLinesInFile (String filename) throws IOException
 Read lines in file list. More...
 
static String readTextFile (String filename) throws IOException
 Ik lees zoek een bestand op het filesysteem en probeer deze als tekstbestand te lezen. More...
 
static String readTextFileAsUtf8 (String filename) throws IOException
 Ik lees zoek een bestand op het filesysteem en probeer deze als tekstbestand met UTF-8 encoding te lezen. More...
 
static StreamSource[] streamSources (String[] bestandsNamen) throws IOException
 Stream sources stream source [ ]. More...
 
static void writeLineToTextFile (String filename, String textLineToAppend) throws IOException
 Write line to text file. More...
 
static void writeLineToTextFile (String filename, String textLineToAppend, boolean append)
 Write line to text file. More...
 
static boolean writeStreamToFile (InputStream inputStream, File file) throws IOException
 Write stream to file boolean. More...
 

Static Public Attributes

static final char CR = '\r'
 The constant CR. More...
 
static final char LF = '\n'
 The constant LF. More...
 

Static Package Attributes

static Path tempDirWithPrefix
 The Temp dir with prefix. More...
 

Static Private Member Functions

static String chomp (String str)
 Remove the last line separator from the input string. More...
 
static Path find (final String fileName)
 
static boolean isEmpty (String str)
 Checks for empty. More...
 
static File[] recursiveDirectoryList (File dir, FilenameFilter filter) throws IOException
 

Static Private Attributes

static Log logger = LogFactory.getLog(nl.psek.fitnesse.fixtures.general.util.FileUtils.class)
 

Detailed Description

A fixture that can be used to generate a (temporary) file, write and read to files and copy files (including over SMB)

Definition at line 28 of file FileUtils.java.

Constructor & Destructor Documentation

◆ FileUtils()

nl.psek.fitnesse.fixtures.general.util.FileUtils.FileUtils ( )

Default constructor.

Definition at line 48 of file FileUtils.java.

Member Function Documentation

◆ chomp()

static String nl.psek.fitnesse.fixtures.general.util.FileUtils.chomp ( String  str)
staticprivate

Remove the last line separator from the input string.

Parameters
strinput string
Returns
cleanded string

Definition at line 575 of file FileUtils.java.

◆ copyFile()

void nl.psek.fitnesse.fixtures.general.util.FileUtils.copyFile ( String  sourceFile,
String  destinationFile 
)

Copies a file from source to target.

Parameters
sourceFilethe source file
destinationFilethe destination file

Definition at line 178 of file FileUtils.java.

◆ copyFileTo()

static boolean nl.psek.fitnesse.fixtures.general.util.FileUtils.copyFileTo ( File  sourceFile,
File  destinationFile 
) throws IOException
static

Ik kopieer een bestand van bron naar bestemming.

Parameters
sourceFilethe source file
destinationFilethe destination file
Returns
boolean boolean
Exceptions
IOExceptionthe io exception

Definition at line 405 of file FileUtils.java.

◆ copyFileToSMBShare()

void nl.psek.fitnesse.fixtures.general.util.FileUtils.copyFileToSMBShare ( String  sourceFile,
String  destinationFile,
String  domain,
String  domainUsername,
String  domainPassword 
)

Copy file to smb share.

Parameters
sourceFilethe source file
destinationFilethe destination file
domainthe domain
domainUsernamethe domain username
domainPasswordthe domain password

Definition at line 198 of file FileUtils.java.

◆ createBinaryTempFile()

static String nl.psek.fitnesse.fixtures.general.util.FileUtils.createBinaryTempFile ( String  filenamePrefix,
String  filenameSuffix,
byte[]  filecontents 
)
static

Creates a temporary binary file.

Parameters
filenamePrefixfilename part added to the beginning of the name of the temporary file
filenameSuffixfilename part added to the end of the name of the temporary file
filecontentsbyte[] content to be written as a file
Returns
the complete file path as a string
Exceptions
StopTestCommandExceptionif an IOException occurs

Definition at line 104 of file FileUtils.java.

◆ createFile()

static void nl.psek.fitnesse.fixtures.general.util.FileUtils.createFile ( File  file) throws IOException
static

Ik maak een nieuw bestand aan als deze nog niet bestaat.

Parameters
filethe file
Exceptions
IOExceptionthe io exception

Definition at line 439 of file FileUtils.java.

◆ createTempFile()

static String nl.psek.fitnesse.fixtures.general.util.FileUtils.createTempFile ( String  filenamePrefix,
String  filenameSuffix,
String  filecontents 
)
static

Creates a temporary UTF-8 file.

Parameters
filenamePrefixfilename part added to the beginning of the name of the temporary file
filenameSuffixfilename part added to the end of the name of the temporary file
filecontentsString content to be written as a file
Returns
the complete file path as a string
Exceptions
StopTestCommandExceptionif an IOException occurs

Definition at line 71 of file FileUtils.java.

◆ deleteFile()

void nl.psek.fitnesse.fixtures.general.util.FileUtils.deleteFile ( String  filename)

Delete een file als deze bestaat.

Parameters
filenamethe filename

Definition at line 454 of file FileUtils.java.

◆ file()

static File nl.psek.fitnesse.fixtures.general.util.FileUtils.file ( String  filename)
static

File file.

Parameters
filenamethe filename
Returns
the file

Definition at line 58 of file FileUtils.java.

◆ fileSearch() [1/2]

static List< File > nl.psek.fitnesse.fixtures.general.util.FileUtils.fileSearch ( File  directory,
boolean  deepSearch,
FileEvaluator  fileEvaluator,
FilenameFilter  filter 
) throws IOException
static

Ik stel een array van.

java.io.File

samen met bestanden in de opgegeven directory. Als er een deepSearch wordt gedaan doe ik dit recursief voor subdirectories. De totale platgeslagen array met File's geef ik vervolgens mee aan de fileSearch() methode, en geef het resultaat daarvan weer terug.

Parameters
directorythe directory
deepSearchthe deep search
fileEvaluatorthe file evaluator
filterthe filter
Returns
list list
Exceptions
IOExceptionthe io exception

Definition at line 489 of file FileUtils.java.

◆ fileSearch() [2/2]

static List< File > nl.psek.fitnesse.fixtures.general.util.FileUtils.fileSearch ( File[]  fileArray,
FileEvaluator  fileEvaluator 
) throws IOException
static

Ik zoek een.

File

in een

File[]

array. Dit doe ik door de meegeleverde FileEvaluator te voorzien van een File uit de array en vervolgens de valid() methode op de evaluator aan te roepen. vervolgens met zoeken.

Parameters
fileArraythe file array
fileEvaluatorthe file evaluator
Returns
list list
Exceptions
IOExceptionthe io exception

Definition at line 528 of file FileUtils.java.

◆ filesInFolder() [1/2]

static List< File > nl.psek.fitnesse.fixtures.general.util.FileUtils.filesInFolder ( File  dir,
String  regexFilePattern 
) throws IOException
static

Files in folder list.

Parameters
dirthe dir
regexFilePatternthe regex file pattern
Returns
the list
Exceptions
IOExceptionthe io exception

Definition at line 351 of file FileUtils.java.

◆ filesInFolder() [2/2]

static List< File > nl.psek.fitnesse.fixtures.general.util.FileUtils.filesInFolder ( String  directory,
String  regexFilePattern 
) throws IOException
static

Files in folder list.

Parameters
directorythe directory
regexFilePatternthe regex file pattern
Returns
the list
Exceptions
IOExceptionthe io exception

Definition at line 368 of file FileUtils.java.

◆ find()

static Path nl.psek.fitnesse.fixtures.general.util.FileUtils.find ( final String  fileName)
staticprivate

Definition at line 555 of file FileUtils.java.

◆ getDatePart()

static int nl.psek.fitnesse.fixtures.general.util.FileUtils.getDatePart ( Date  date,
int  calendarPart 
)
static

Gets date part.

Parameters
datethe date
calendarPartthe calendar part
Returns
the date part

Definition at line 470 of file FileUtils.java.

◆ getFileSize()

long nl.psek.fitnesse.fixtures.general.util.FileUtils.getFileSize ( String  location)

Gets file size.

Parameters
locationthe location
Returns
the file size

Definition at line 163 of file FileUtils.java.

◆ isEmpty()

static boolean nl.psek.fitnesse.fixtures.general.util.FileUtils.isEmpty ( String  str)
staticprivate

Checks for empty.

Parameters
strinput string
Returns
boolean

Definition at line 607 of file FileUtils.java.

◆ readFile()

static String nl.psek.fitnesse.fixtures.general.util.FileUtils.readFile ( final String  fileName,
final String  encoding 
) throws IOException
static

Read file string.

Parameters
fileNamethe file name
encodingthe encoding
Returns
the string
Exceptions
IOExceptionthe io exception

Definition at line 549 of file FileUtils.java.

◆ readLinesInFile()

static List< String > nl.psek.fitnesse.fixtures.general.util.FileUtils.readLinesInFile ( String  filename) throws IOException
static

Read lines in file list.

Parameters
filenamethe filename
Returns
the list
Exceptions
IOExceptionthe io exception

Definition at line 311 of file FileUtils.java.

◆ readTextFile()

static String nl.psek.fitnesse.fixtures.general.util.FileUtils.readTextFile ( String  filename) throws IOException
static

Ik lees zoek een bestand op het filesysteem en probeer deze als tekstbestand te lezen.

Vervolgens geef ik de gelezen tekst als String terug.

Ik verwijder de laatste line separator uit de teruggegeven string

Parameters
filenamethe filename
Returns
string string
Exceptions
IOExceptionthe io exception

Definition at line 227 of file FileUtils.java.

◆ readTextFileAsUtf8()

static String nl.psek.fitnesse.fixtures.general.util.FileUtils.readTextFileAsUtf8 ( String  filename) throws IOException
static

Ik lees zoek een bestand op het filesysteem en probeer deze als tekstbestand met UTF-8 encoding te lezen.

Vervolgens geef ik de gelezen tekst als String terug.

Ik verwijder de laatste line separator uit de teruggegeven string

Parameters
filenamethe filename
Returns
string string
Exceptions
IOExceptionthe io exception

Definition at line 251 of file FileUtils.java.

◆ recursiveDirectoryList()

static File[] nl.psek.fitnesse.fixtures.general.util.FileUtils.recursiveDirectoryList ( File  dir,
FilenameFilter  filter 
) throws IOException
staticprivate

Definition at line 504 of file FileUtils.java.

◆ streamSources()

static StreamSource[] nl.psek.fitnesse.fixtures.general.util.FileUtils.streamSources ( String[]  bestandsNamen) throws IOException
static

Stream sources stream source [ ].

Parameters
bestandsNamenthe bestands namen
Returns
the stream source [ ]
Exceptions
IOExceptionthe io exception

Definition at line 330 of file FileUtils.java.

◆ verifyFileExists()

boolean nl.psek.fitnesse.fixtures.general.util.FileUtils.verifyFileExists ( String  location)

Verifies that a file exists.

Parameters
locationthe location
Returns
the boolean

Definition at line 130 of file FileUtils.java.

◆ verifySMBFileExists()

boolean nl.psek.fitnesse.fixtures.general.util.FileUtils.verifySMBFileExists ( String  location,
String  domain,
String  domainUser,
String  domainPassword 
)

Verify smb file exists boolean.

Parameters
locationthe location
domainthe domain
domainUserthe domain user
domainPasswordthe domain password
Returns
the boolean

Definition at line 144 of file FileUtils.java.

◆ writeLineToTextFile() [1/2]

static void nl.psek.fitnesse.fixtures.general.util.FileUtils.writeLineToTextFile ( String  filename,
String  textLineToAppend 
) throws IOException
static

Write line to text file.

Parameters
filenamethe filename
textLineToAppendthe text line to append
Exceptions
IOExceptionthe io exception

Definition at line 271 of file FileUtils.java.

◆ writeLineToTextFile() [2/2]

static void nl.psek.fitnesse.fixtures.general.util.FileUtils.writeLineToTextFile ( String  filename,
String  textLineToAppend,
boolean  append 
)
static

Write line to text file.

Parameters
filenamethe filename
textLineToAppendthe text line to append
appendboolean toggle to append to the file (append=true) or to overwrite (append=false)

Definition at line 282 of file FileUtils.java.

◆ writeStreamToFile()

static boolean nl.psek.fitnesse.fixtures.general.util.FileUtils.writeStreamToFile ( InputStream  inputStream,
File  file 
) throws IOException
static

Write stream to file boolean.

Parameters
inputStreamthe input stream
filethe file
Returns
the boolean
Exceptions
IOExceptionthe io exception

Definition at line 421 of file FileUtils.java.

Member Data Documentation

◆ CR

final char nl.psek.fitnesse.fixtures.general.util.FileUtils.CR = '\r'
static

The constant CR.

Definition at line 38 of file FileUtils.java.

◆ LF

final char nl.psek.fitnesse.fixtures.general.util.FileUtils.LF = '\n'
static

The constant LF.

Definition at line 34 of file FileUtils.java.

◆ logger

Log nl.psek.fitnesse.fixtures.general.util.FileUtils.logger = LogFactory.getLog(nl.psek.fitnesse.fixtures.general.util.FileUtils.class)
staticprivate

Definition at line 30 of file FileUtils.java.

◆ tempDirWithPrefix

Path nl.psek.fitnesse.fixtures.general.util.FileUtils.tempDirWithPrefix
staticpackage

The Temp dir with prefix.

Definition at line 43 of file FileUtils.java.


The documentation for this class was generated from the following file: