public abstract class Uploader
extends java.lang.Object
Class to create and use instances to upload binary, delimited and xml formatted files to the server. Configuration options are documented for each uploader type.
In interest of performance uploaders do not provide extensive data validations. While erroneous data will be trapped, exception and messages may not be very apt. So user code will have to be ready to trap all exceptions, including NullPointerException and provide the user with a more appropriate feedback.
| Modifier and Type | Class and Description |
|---|---|
static class |
Uploader.RegistrationType
Type of callback to generate
|
| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
m_benchHost |
int |
m_benchPort |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Must be called after upload has finished to release resources
|
void |
closeNow() |
void |
connect(java.lang.String uri,
Credentials creds,
int blockSize)
Connects the uploader to the target project running in the server framework.
|
void |
connect(java.lang.String host,
int port,
Credentials creds,
int blocksize)
Connect to a standalone project.
|
static Uploader |
createBinaryUploader()
Creates an uninitialized binary file uploader.
|
static Uploader |
createDelimitedUploader(boolean hasStreamAndOp)
Creates an uploader to upload files containing delimited data.
|
static Uploader |
createXmlUploader()
Creates an uploader to upload files that contain data in pseudo XML format.
|
int |
getBlockSize()
Returns the block size currently in effect
|
abstract long |
getProcessRecords()
Get number of records currently processed
|
abstract long |
profile(java.io.File file)
Utility methods that can be used to check disk access times.
|
void |
registerListener(ProgressListener listener,
Uploader.RegistrationType type,
long interval)
Register a listener to be informed of progess and/or errors.
|
void |
setDateFormat(java.lang.String format)
Ignored for binary uploaders.
|
void |
setDelimiter(char delim)
Override the default delimiter in delimited uploader.
|
void |
setOperation(Stream.Operation op)
This overrides the opcode in the data being uploaded.
|
void |
setStream(java.lang.String streamName)
This overrides the target stream if any in the data being uploaded.
|
void |
setTimestampFormat(java.lang.String format)
Ignored for binary uploaders.
|
long |
upload(java.io.File file)
Start upload of the specified file.
|
public static Uploader createBinaryUploader()
Creates an uninitialized binary file uploader. The uploader is used to upload files containing preformatted binary data, typically produced by esp_convert or similar utilities. The file must contain data that matches the architecture of the target machine, Uploader does not perform any validations on endianness.
A binary uploader can be customized by specifying a block size during connect and overriding the target stream using setStream(String)
public static Uploader createDelimitedUploader(boolean hasStreamAndOp)
These defaults can be changed by setDelimiter(char), setStream(String) and setOperation(com.sybase.esp.sdk.Stream.Operation).
Recognized opcode strings are as follows
hasStreamAndOp - true if the file contains the stream name and opcode as the first two columns,
false otherwisepublic static Uploader createXmlUploader()
Creates an uploader to upload files that contain data in pseudo XML format. There is no root element. Each line in the file must contain a valid XML node corresponding to a single data row. The name of the node corresponds to the name of the stream to publish the data to.
The uploader recognizes a special field called ESP_OPS which contains the operation code. Recognized opcode strings are as follows
The default target stream can be changed using setStream(String) and the default operation can be set using setOperation(com.sybase.esp.sdk.Stream.Operation).
public void connect(java.lang.String uri,
Credentials creds,
int blockSize)
throws EntityNotFoundException,
java.io.IOException,
javax.security.auth.login.LoginException,
ServerErrorException
NOTE: if the file contains data for multiple streams, specifying a block size will throw an exception during publishing.
uri - project uricreds - credentials to use to authenticateblockSize - 0 or negative means no blocking will be doneEntityNotFoundExceptionjava.io.IOExceptionjavax.security.auth.login.LoginExceptionServerErrorExceptionpublic void connect(java.lang.String host,
int port,
Credentials creds,
int blocksize)
throws java.io.IOException,
javax.security.auth.login.LoginException,
EntityNotFoundException,
ServerErrorException
host - command control hostport - command control portcreds - credentials to use to connectblocksize - if 0 or negative not blocking will be donejava.io.IOExceptionjavax.security.auth.login.LoginExceptionEntityNotFoundExceptionServerErrorExceptionpublic void close()
throws java.io.IOException
java.io.IOExceptionpublic void closeNow()
public void setDelimiter(char delim)
delim - public void setStream(java.lang.String streamName)
This overrides the target stream if any in the data being uploaded. If uploading delimited data that does not contain a stream name this must be set.
streamName - public void setOperation(Stream.Operation op)
This overrides the opcode in the data being uploaded. Is ignored for binary uploaders. If uploading delimited data that does not contain an opcode this must be set.
op - public void setDateFormat(java.lang.String format)
Ignored for binary uploaders. Format string to use to parse fields of type Schema.DataType#DATE Patterns accepted are the same as for java.text.SimpleDateFormat.
The default date format is "yyyy-MM-dd'T'hh:mm:ss".
format - public void setTimestampFormat(java.lang.String format)
The default timestamp format is the same as the default date format but optionally recognizes a period followed 3 digit millisecond value.
format - public int getBlockSize()
public long upload(java.io.File file)
throws UploadException,
java.io.FileNotFoundException,
java.io.IOException,
java.text.ParseException
file - java.io.IOExceptionjava.text.ParseExceptionUploadExceptionjava.io.FileNotFoundExceptionpublic abstract long profile(java.io.File file)
throws java.io.IOException
Note: Currently implemented only for binary uploader. This will likely go away
file - java.io.IOExceptionpublic void registerListener(ProgressListener listener, Uploader.RegistrationType type, long interval)
listener - interval - If registration type is Uploader.RegistrationType.COUNT_BYTES the callback will
happen every 'interval' bytes. If type is Uploader.RegistrationType.COUNT_RECORDS callback will
happen every 'interval' recordspublic abstract long getProcessRecords()