com.alarexgroup.m2mplf.file
Class File

java.lang.Object
  extended by com.alarexgroup.m2mplf.file.File
public class File
extends java.lang.Object

Class for work with files in module memory. This class encapsulates original FileConnection - for easier usage.

Example - creating and recor into file:

File file = new File("a:/test.txt");
file.create();
OutputStream os = file.openForWrite();
try {
  os.write(Hello.getBytes());
    catch (IOException ex) {
         Logger.logError(It fell down again!!");
  Logger.logError(ex);
    }
file.close();


Example - does the file exist?

 File file = new File("a:/testx.txt");
 if (file.exists()) Logger.logInfo(File exists!);
 else Logger.logInfo(File doesn't exist!");
 

Constructor Summary
File(java.lang.String fileName)
          Creates file instance
 
Method Summary
 void close()
          Finish the work with file and unblock the sources.
 boolean create()
          Creates physically new file.
 boolean delete()
          Erease file
 boolean exists()
          Detect if the file existed.
 long fileSize()
          Returns file size.
 boolean isHidden()
          Tests if the file was hidden.
 java.io.InputStream openForRead()
          Opens file for reading.
 java.io.OutputStream openForWrite()
          Opens file for record.
 java.io.OutputStream openForWrite(long offset)
           
 boolean rename(java.lang.String name)
          Rename file.
 boolean setHidden(boolean hidden)
          Sets file as a hidden file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

File

public File(java.lang.String fileName)
Creates file instance

Parameters:
fileName - full path to file, for example: A:/mujsoubor.dat
Method Detail

create

public boolean create()
Creates physically new file. If the file already existed, is overwritten by new file.

Returns:
True - seccessfully created
False - to create new file wasn't possible, log. file includes details

openForRead

public java.io.InputStream openForRead()
Opens file for reading.

Returns:
References to InputStream of open file. If was NULL, file wasn't possible open, log. file includes details.

openForWrite

public java.io.OutputStream openForWrite()
Opens file for record.

Returns:
Returns OutputStream of open file. If was NULL, file wasn't possible open, log. file includes details.

openForWrite

public java.io.OutputStream openForWrite(long offset)

rename

public boolean rename(java.lang.String name)
Rename file. Closes InputStream and OutputStream.

Parameters:
name - new file name, without path specification.
Returns:
True - success

delete

public boolean delete()
Erease file

Returns:
True - success

exists

public boolean exists()
Detect if the file existed.

Returns:
True - exists False - doesn't exist

fileSize

public long fileSize()
Returns file size.

Returns:
File size -1 - unavailable file or it doesn't exist -2 - other problem, log. file includes details.

setHidden

public boolean setHidden(boolean hidden)
Sets file as a hidden file.

Parameters:
hidden - True - hide False - show
Returns:
True - success

isHidden

public boolean isHidden()
Tests if the file was hidden.

Returns:
TRUE - hidden file

close

public void close()
Finish the work with file and unblock the sources.