Methods Summary |
---|
public boolean | close(java.io.InputStream stream)Close the given stream ignoring any exception.
Returns true, if the stream was closed successfully, false otherwise
if ( stream == null )
{
return false ;
}
try
{
stream.close() ;
return true ;
}
catch (IOException e)
{
return false ;
}
|
public boolean | close(java.io.OutputStream stream)Close the given stream ignoring any exception.
Returns true, if the stream was closed successfully, false otherwise
if ( stream == null )
{
return false ;
}
try
{
stream.close() ;
return true ;
}
catch (IOException e)
{
return false ;
}
|
public void | copyStream(java.io.InputStream inStream, java.io.OutputStream outStream)Copies all data from the iniput stream to the output stream using
a buffer with the default size (1024 bytes).
After all data is copied both streams will be closed !
this.copyStream( inStream, outStream, DEFAULT_BUFFER_SIZE ) ;
|
public void | copyStream(java.io.InputStream inStream, java.io.OutputStream outStream, int bufSize)Copies all data from the iniput stream to the output stream using
a buffer of the given size in bytes.
After all data is copied both streams will be closed !
byte[] buffer = new byte[bufSize] ;
int count ;
try
{
count = inStream.read(buffer) ;
while ( count > -1 )
{
outStream.write( buffer, 0, count ) ;
count = inStream.read(buffer) ;
}
}
finally
{
this.close(inStream) ;
this.close(outStream) ;
}
|
protected void | copyText(java.io.InputStream inStream, java.io.StringWriter writer)
this.copyText( new InputStreamReader( inStream ), writer ) ;
|
public void | copyText(java.io.Reader reader, java.io.StringWriter writer)Copies all text lines from the specified reader to the given writer.
After that the reader will be closed. Even if an exception occurs.
BufferedReader bufReader ;
String line ;
LineProcessor processor ;
bufReader = new BufferedReader( reader ) ;
try
{
processor = new LineProcessor()
{
public boolean processLine( String line, int lineNo )
{
if ( lineNo > 1 )
writer.write( LINE_SEPARATOR ) ;
writer.write( line ) ;
return true ;
}
} ;
this.processTextLines( bufReader, processor ) ;
}
finally
{
bufReader.close() ;
}
|
public static org.pf.file.FileUtil | current()
return current ;
|
protected int | indexOfPreceedingNotNullElement(java.lang.String[] elements, int start)
for (int i = start; i >= 0 ; i--)
{
if ( elements[i] != null )
{
if ( "..".equals( elements[i] ) ) // This is not a valid not null element
{
return -1 ;
}
else
{
return i ;
}
}
}
return -1 ;
|
public java.lang.String | javaFilename(java.lang.String filename)Returns the given filename in the platform independent way that Java
understands. That is all elements are separated by a forward slash rather
than back slashes as on Windows systems.
if ( filename == null )
return null ;
return filename.replace( '\\", '/" ) ;
|
public void | processTextLines(java.io.InputStream inStream, LineProcessor processor)Reads all text lines from the specified input stream and passes them
one by one to the given line processor.
The processing will be terminated, if the end of the text is reached or
if the processor returns false.
The given input stream will be closed after the execution of this method.
Even if an exception occured.
InputStreamReader reader ;
if ( inStream == null )
throw new IllegalArgumentException( "inStream must not be null" ) ;
reader = new InputStreamReader( inStream ) ;
this.processTextLines( reader, processor ) ;
|
public void | processTextLines(java.io.Reader reader, LineProcessor processor)Reads all text lines from the specified reader and passes them one by one
to the given line processor.
The processing will be terminated, if the end of the text is reached or
if the processor returns false.
BufferedReader bufReader ;
String line ;
int counter = 0 ;
boolean continue_reading = true ;
if ( reader == null )
throw new IllegalArgumentException( "reader must not be null" ) ;
if ( processor == null )
throw new IllegalArgumentException( "processor must not be null" ) ;
bufReader = new BufferedReader( reader ) ;
while ( continue_reading && bufReader.ready() )
{
line = bufReader.readLine() ;
if ( line == null )
break ;
counter++ ;
continue_reading = processor.processLine( line, counter ) ;
}
|
public void | processTextLines(java.lang.String filename, LineProcessor processor)Reads all text lines from the file with the specified name and passes them
one by one to the given line processor.
The processing will be terminated, if the end of the text is reached or
if the processor returns false.
FileInputStream inStream ;
if ( filename == null )
throw new IllegalArgumentException( "filename must not be null" ) ;
inStream = new FileInputStream( filename ) ;
this.processTextLines( inStream, processor ) ;
|
public java.lang.String | readTextFrom(java.io.InputStream inStream)Reads the whole content of the given input stream and returns
it as a string.
The stream will be closed after calling this method. Even if an exception
occured!
StringWriter writer ;
writer = new StringWriter( 1024 ) ;
this.copyText( inStream, writer ) ;
return writer.toString() ;
|
public java.lang.String | readTextFrom(java.lang.String filename)Reads the whole content of the file with the given name and returns
it as a string.
FileInputStream inStream ;
inStream = new FileInputStream( filename ) ;
return this.readTextFrom( inStream ) ;
|
public java.lang.String | readTextFrom(java.io.File file)Reads the whole content of the specified file and returns
it as a string.
FileInputStream inStream ;
inStream = new FileInputStream( file ) ;
return this.readTextFrom( inStream ) ;
|
public java.lang.String | standardize(java.lang.String filename)Convert the filename to a canonical (see java.io.File.getCanonicalPath())
format and replace any backslashes '\' by slashes ('/').
If possible all "." and ".." elements in the path are eliminated.
if ( filename == null )
return null ;
return this.standardizeFilename( filename ) ;
|
protected java.lang.String | standardizeFilename(java.lang.String filename)
String[] nameElements ;
boolean hasDriveLetter ;
boolean startedFromRoot ;
boolean isAbsolute ;
int index ;
filename = this.javaFilename(filename) ;
startedFromRoot = filename.startsWith( "/" ) ;
nameElements = this.str().parts( filename, "/" ) ;
if ( nameElements.length > 0 )
{
hasDriveLetter = nameElements[0].endsWith( ":" ) ;
if ( hasDriveLetter )
{
nameElements[0] = nameElements[0].toUpperCase() ;
}
else
{
if ( startedFromRoot )
{
nameElements = this.str().append( new String[] { "" }, nameElements );
}
}
isAbsolute = hasDriveLetter || startedFromRoot ;
for (int i = 0; i < nameElements.length; i++)
{
if ( ".".equals( nameElements[i] ) )
{
nameElements[i] = null ;
}
else
{
if ( "..".equals( nameElements[i] ) )
{
index = this.indexOfPreceedingNotNullElement( nameElements, i-1 ) ;
if ( index >= 0 )
{
if ( ( index > 0 ) || ( ! isAbsolute ) )
{
nameElements[i] = null ;
nameElements[index] = null ;
}
}
}
}
}
nameElements = this.str().removeNull( nameElements ) ;
return this.str().asString( nameElements, "/" ) ;
}
else
{
return "" ;
}
|
protected org.pf.text.StringUtil | str()
return StringUtil.current() ;
|