net.fsp
Class FSPutil

java.lang.Object
  extended by net.fsp.FSPutil

public class FSPutil
extends java.lang.Object

Utilities for easier working with FSP.

There are some higher level function for working with FSP.

Since:
1.0
Version:
1.0rc7
Author:
Radim Kolar

Constructor Summary
FSPutil()
           
 
Method Summary
static boolean canUpload(FSPsession session, java.lang.String filename)
          Checks if user have enough rights to upload given file.
static void download(FSPsession session, java.lang.String filename, java.io.OutputStream os, long start_from, long byteswanted)
          Downloads a file from FSP server.
static java.lang.String[] list(FSPsession session, java.lang.String directory)
          get a filename directory list from server.
static FSPstat stat(FSPsession session, java.lang.String path)
          Gets information about file or directory.
static FSPstat[] statlist(FSPsession session, java.lang.String directory)
          get a FSPstat directory list from server.
static boolean statSupported(FSPsession session)
          Check if FSP server supports CC_STAT command.
static byte[] stringToASCIIZ(java.lang.String filename)
          Converts String to ASCIIZ byte array.
static void upload(FSPsession session, java.lang.String filename, java.io.InputStream is, long timestamp)
          Uploads file to FSP server
static FSPversion version(FSPsession session)
          Sends CC_VERSION command to server and parses reply.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FSPutil

public FSPutil()
Method Detail

download

public static void download(FSPsession session,
                            java.lang.String filename,
                            java.io.OutputStream os,
                            long start_from,
                            long byteswanted)
                     throws java.io.IOException
Downloads a file from FSP server.

This procedure download a file from FSP server, file is written to OutputStream. OutputStream is not closed at end of transfer.

Parameters:
session - active FSP session
filename - filename on FSP server
os - write file to this stream
start_from - offset where to start download
byteswanted - how many bytes to download, < 0 for all
Throws:
java.io.IOException - if i/o or net error ocured during file transfer
Since:
1.0

upload

public static void upload(FSPsession session,
                          java.lang.String filename,
                          java.io.InputStream is,
                          long timestamp)
                   throws java.io.IOException
Uploads file to FSP server

Parameters:
session - opened FSPsession to target server
filename - filename on remote server
is - InputStream to be sent to server. Stream is not closed at end of operation
timestamp - timestamp for uploaded file, 0 if not used. Timestamp in in standard Java format (milliseconds)
Throws:
java.io.IOException - if i/o or net error ocured during file transfer
Since:
1.0rc7

stat

public static FSPstat stat(FSPsession session,
                           java.lang.String path)
                    throws java.io.IOException
Gets information about file or directory.

This function requests information about specific path from FSP server. Server must support CC_STAT command, which is supported from FSP 2.8.1 Beta 11.

Parameters:
session - FSPsession
path - path for getting information
Returns:
FSPstat object or null if path is not found
Throws:
java.io.IOException - if server is not responding or do not supports CC_STAT command
Since:
1.0
See Also:
FSPstat, statSupported(FSPsession)

statSupported

public static boolean statSupported(FSPsession session)
                             throws java.io.IOException
Check if FSP server supports CC_STAT command. This command is implemented in fspd from FSP suite version 2.8.1 Beta 11 or later.

This function is also suitable for detecting if FSP server is still alive. If you dont get IOException during function call then you are still connected to FSP server.

Parameters:
session - FSPsession
Returns:
true if CC_STAT command is supported
Throws:
java.io.IOException - if server can not be contacted
Since:
1.0

stringToASCIIZ

public static byte[] stringToASCIIZ(java.lang.String filename)
Converts String to ASCIIZ byte array.

Parameters:
filename - string to be converted
Returns:
converted byte array NULL terminated
Since:
1.0

list

public static java.lang.String[] list(FSPsession session,
                                      java.lang.String directory)
                               throws java.io.IOException
get a filename directory list from server.

Parameters:
session - live FSPsession
directory - directory to be listed
Returns:
file list
Throws:
java.io.IOException - if network failure ocurs
Since:
1.0

statlist

public static FSPstat[] statlist(FSPsession session,
                                 java.lang.String directory)
                          throws java.io.IOException
get a FSPstat directory list from server.

Parameters:
session - live FSPsession
directory - directory to be listed
Returns:
FSPstat list or null on error
Throws:
java.io.IOException - if network error ocurs
Since:
1.0
See Also:
FSPstat

version

public static FSPversion version(FSPsession session)
                          throws java.io.IOException
Sends CC_VERSION command to server and parses reply. Because some servers do not reply to CC_VERSION command, it should not be used for detection if FSPsession is still alive. Better is to use statSupported function instead.

Parameters:
session - live FSPsession
Returns:
FSPversion object
Throws:
java.io.IOException
Since:
1.0rc7
See Also:
statSupported(FSPsession)

canUpload

public static boolean canUpload(FSPsession session,
                                java.lang.String filename)
                         throws java.io.IOException
Checks if user have enough rights to upload given file.

Parameters:
session - opened FSPsession
filename - file to be uploaded
Returns:
true if user can upload file
Throws:
java.io.IOException
Since:
1.0rc8


Copyright © 2009 FSP Project. All Rights Reserved.