Compact Class For Java – CCFile


Compact Class is a collection of common functions and classes that can make your code more concise, fast, and precise.

utility

Class CCFile

java.lang.Object

extended by

utility.CCSystem

extended by

utility.CCFile

public class CCFileextends CCSystem

CCFile is a collection method that is used to open, read, write, save, and
manipulate files.

Since:
10.03.17
Version:
12.03.17
Author:
Yosua Onesimus


Constructor Detail

CCFile

public CCFile()


Method Detail

showOpenDialog

public static java.io.File showOpenDialog(java.io.File currentDirectory,
                                          int fileSelectionMode,
                                          java.lang.String... endsWiths)
Returns the selected file. This can be set either by the programmer via
setFile or by a user action, such as either typing the filename into the
UI or selecting the file from a list in the UI.

 

Parameters:
currentDirectory– the current directory to point to.
fileSelectionMode– the type of files to be displayed.
endsWiths

 

Returns:the selected fileSee Also:JFileChooser.FILES_ONLY,
JFileChooser.DIRECTORIES_ONLY,
JFileChooser.FILES_AND_DIRECTORIES


showOpenDialog

public static java.io.File showOpenDialog(java.lang.String... endsWiths)
Returns the selected file. This can be set either by the programmer via
setFile or by a user action, such as either typing the filename into the
UI or selecting the file from a list in the UI.
Same as :
 showOpenDialog(_newFile(CCPath.getApplPath()), JFileChooser.FILES_ONLY, endsWiths);

 

Parameters:
endsWiths

 

Returns:the selected file


showSaveDialog

public static java.io.File showSaveDialog(java.io.File currentDirectory,
                                          int fileSelectionMode,
                                          java.lang.String... endsWiths)
Returns the selected file. This can be set either by the programmer via
setFile or by a user action, such as either typing the filename into the
UI or selecting the file from a list in the UI.

 

Parameters:
currentDirectory– the current directory to point to.
fileSelectionMode– the type of files to be displayed.
endsWiths

 

Returns:the selected fileSee Also:JFileChooser.FILES_ONLY,
JFileChooser.DIRECTORIES_ONLY,
JFileChooser.FILES_AND_DIRECTORIES


showSaveDialog

public static java.io.File showSaveDialog(java.lang.String... endsWiths)
Returns the selected file. This can be set either by the programmer via
setFile or by a user action, such as either typing the filename into the
UI or selecting the file from a list in the UI.
Same as :
 showSaveDialog(_newFile(CCPath.getApplPath()), JFileChooser.FILES_ONLY, endsWiths);

 

Parameters:
endsWiths

 

Returns:the selected file


getFileNameNextSequence

public static java.lang.String getFileNameNextSequence(java.lang.String filePath,
                                                       java.lang.String fileNameFormat,
                                                       int sequenceLength)
Parameters:
filePath
fileNameFormat– Example: log[].txt
sequenceLength

Returns:fileName


readByteA

public static byte[] readByteA(java.io.File file)
Reads up to b.length bytes of data from this input stream into an array
of bytes. This method blocks until some input is available.

 

Parameters:
file – the file to be opened for reading.

 

Returns:byteA the buffer into which the data is read.


readByteA

public static byte[] readByteA(java.lang.String pathname)
Reads up to b.length bytes of data from this input stream into an array
of bytes. This method blocks until some input is available.
Same as
:
 readByteA(newFile(pathname));

 

Parameters:
pathname – A pathname the file to be opened for reading.

 

Returns:byteA the buffer into which the data is read.


writeByteA

public static boolean writeByteA(byte[] content,
                                 java.io.File file)
Writes b.length bytes from the specified byte array to this file output
stream.

 

Parameters:
content– the data.
file – the file to be opened for writing.

 

Returns:boolean


writeByteA

public static boolean writeByteA(byte[] content,
                                 java.lang.String pathname)
Writes b.length bytes from the specified byte array to this file output
stream.
Same as :
 writeByteA(content, newFile(pathname));

 

Parameters:
content– the data.
pathname – A pathname the file to be opened for writing.

 

Returns:boolean


readList

public static java.util.List<java.lang.String> readList(java.io.File file)
Read List from file.

 

Parameters:
file – the File to read from.

 

Returns:strings


readList

public static java.util.List<java.lang.String> readList(java.lang.String pathname)
Read List from file.
Same as :
 readList(newFile(pathname));

 

Parameters:
pathname – A pathname the File to read from.

 

Returns:strings


writeList

public static boolean writeList(java.util.List<java.lang.String> contents,
                                java.io.File file)
Write List to file.

 

Parameters:
contents
file – a File object to write to.

 

Returns:boolean


writeList

public static boolean writeList(java.util.List<java.lang.String> strings,
                                java.lang.String pathname)
Write List to file.
Same as :
 writeList(strings, newFile(pathname));

 

Parameters:
strings
pathname – A pathname a File object to write to.

 

Returns:boolean


readObject

public static java.lang.Object readObject(java.io.File file)
Read an object from the ObjectInputStream. The class of the object, the
signature of the class, and the values of the non-transient and
non-static fields of the class and all of its supertypes are read.

 

Parameters:
file – the file to be opened for reading.

 

Returns:Object the object read from the stream.


readObject

public static java.lang.Object readObject(java.lang.String pathname)
Read an object from the ObjectInputStream. The class of the object, the
signature of the class, and the values of the non-transient and
non-static fields of the class and all of its supertypes are read.

Same as :

 readObject(newFile(pathname));

 

Parameters:
pathname – A pathname the file to be opened for reading.

 

Returns:Object the object read from the stream.


writeObject

public static boolean writeObject(java.lang.Object object,
                                  java.io.File file)
Write the specified object to the ObjectOutputStream. The class of the
object, the signature of the class, and the values of the non-transient
and non-static fields of the class and all of its supertypes are written.

 

Parameters:
object– the object to be written
file – the file to be opened for writing.

 

Returns:boolean


writeObject

public static boolean writeObject(java.lang.Object object,
                                  java.lang.String pathname)
Write the specified object to the ObjectOutputStream. The class of the
object, the signature of the class, and the values of the non-transient
and non-static fields of the class and all of its supertypes are
written.
Same as :
 writeObject(object, newFile(pathname));

 

Parameters:
object– the object to be written.
pathname – A pathname the file to be opened for writing.

 

Returns:boolean


getFileName

public static java.lang.String getFileName(java.lang.Class clazz,
                                           java.lang.Long id)
Parameters:
clazz
id

Returns:fileName clazz.getSimpleName() + “.” + id;


getFileName

public static java.lang.String getFileName(CCEntity entity)
Same as :
 getFileName(entity.getClass(), entity.getId());

 

Parameters:
entity

 

Returns:fileName clazz.getSimpleName() + “.” + id;


readObject

public static java.lang.Object readObject(java.lang.Class clazz,
                                          java.lang.Long id)
Read an object from the ObjectInputStream. The class of the object, the
signature of the class, and the values of the non-transient and
non-static fields of the class and all of its supertypes are read.

Same as :

 readObject(newFile(getFileName(clazz, id)));

 

Parameters:
clazz
id

 

Returns:Object the object read from the stream.


readObject

public static java.lang.Object readObject(CCEntity entity)
Read an object from the ObjectInputStream. The class of the object, the
signature of the class, and the values of the non-transient and
non-static fields of the class and all of its supertypes are read.

Same as :

 readObject(newFile(getFileName(clazz, id)));

 

Parameters:
entity

 

Returns:Object the object read from the stream.


writeObject

public static boolean writeObject(CCEntity entity)
Write the specified object to the ObjectOutputStream. The class of the
object, the signature of the class, and the values of the non-transient
and non-static fields of the class and all of its supertypes are
written.
Same as :
 writeObject(entity, getFileName(entity));

 

Parameters:
entity – the object to be written

 

Returns:boolean


readString

public static java.lang.String readString(java.io.File file)
Read String from file.

 

Parameters:
file – the File to read from.

 

Returns:string A String containing the contents of the line, not
including any line-termination characters, or null if the end of the
stream has been reached.


readString

public static java.lang.String readString(java.lang.String pathname)
Read String from file.
Same as :
 readString(newFile(pathname));

 

Parameters:
pathname – A pathname the File to read from.

 

Returns:string A String containing the contents of the line, not
including any line-termination characters, or null if the end of the
stream has been reached.


writeString

public static boolean writeString(java.lang.String content,
                                  java.io.File file)
Write String to file.

 

Parameters:
content– String to be written.
file – a File object to write to.

 

Returns:boolean


writeString

public static boolean writeString(java.lang.String content,
                                  java.lang.String pathname)
Write String to file.
Same as :
 writeString(content, newFile(pathname));

 

Parameters:
content– String to be written.
pathname – A pathname a File object to write to.

 

Returns:boolean


copy

public static boolean copy(java.io.InputStream inputStream,
                           java.io.OutputStream outputStream)
Copies inputStream to another outputStream.

 

Parameters:
inputStream
outputStream

 

Returns:boolean


copy

public static boolean copy(java.io.File source,
                           java.io.File destination,
                           boolean hierarchy,
                           java.lang.String type)
Copies one or more files to another location.

 

Parameters:
source
destination
hierarchy
type

 

Returns:boolean


copy

public static boolean copy(java.io.File source,
                           java.io.File destination)
Copies one or more files to another location.
Same as :
 copy(source, destination, true, null);

 

Parameters:
source
destination

 

Returns:boolean


copy

public static boolean copy(java.lang.String source,
                           java.lang.String destination)
Copies one or more files to another location.
Same as :
 copy(newFile(source), newFile(destination));

 

Parameters:
source
destination

 

Returns:boolean


delete

public static boolean delete(java.io.File source)
Delete one or more files.

 

Parameters:
source

 

Returns:boolean


delete

public static boolean delete(java.lang.String source)
Delete one or more files.
Same as :
 delete(newFile(source));

 

Parameters:
source

 

Returns:boolean


rename

public static boolean rename(java.io.File source,
                             java.io.File destination)
Renames the file denoted by this abstract pathname.

 

Parameters:
source
destination – The new abstract pathname for the named file

 

Returns:boolean


rename

public static boolean rename(java.lang.String source,
                             java.lang.String destination)
Renames the file denoted by this abstract pathname.
Same as :
 rename(newFile(source), newFile(destination));

 

Parameters:
source
destination

 

Returns:boolean


browse

public static void browse(java.lang.String url)
Launches the default browser to display a URI.

 

Parameters:
url – the URI to be displayed in the user default browser.

 


open

public static void open(java.io.File file)
Launches the associated application to open the file.

 

Parameters:
file – the file to be opened with the associated application.

 


exec

public static java.lang.Process exec(java.lang.String command)
Executes the specified string command in a separate process.

 

Parameters:
command – a specified system command.

 

Returns:A new Process object for managing the subprocess


exec

public static java.lang.Process exec(java.lang.String... arrayCommand)
Executes the specified command and arguments in a separate process.

 

Parameters:
arrayCommand – array containing the command to call and its
arguments.

 

Returns:A new Process object for managing the subprocess


execBatch

public static java.lang.Process execBatch(java.lang.String filepath)
Executes the specified string command in a separate process.

 

Parameters:
filepath

 

Returns:A new Process object for managing the subprocess


execViaShell

public static java.lang.Process execViaShell(java.lang.String command)
Executes the specified command and arguments with shell.

 

Parameters:
command

 

Returns:Process Usually empty..😀


getLog

public static java.util.List<java.lang.String> getLog(java.lang.Process process)
Get list of log from process.

 

Parameters:
process

 

Returns:strings


getDateCreated

public static java.util.Date getDateCreated(java.io.File file)
Get created date from file.

 

Parameters:
file

 

Returns:Date


getListOrderByDateCreated

public static java.util.List<CCFile.FileInfo> getListOrderByDateCreated(java.io.File path)
Get list of file info from path.

 

Parameters:
path

 

Returns:List


getMotherboardSerialNumber

public static java.lang.String getMotherboardSerialNumber()
Returns:
motherboard serial number

getHarddiskSerialNumber

public static java.lang.String getHarddiskSerialNumber(java.lang.String drive)
Parameters:
drive

Returns:harddisk serial number


getMacAddress

public static java.lang.String getMacAddress()
Returns:
mac address
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: