1 Ax.sql.Blob

Provides an in memory empty Blob object ready to be filled. When creating the class, you can provide a virtual file name appearing as the name of content.

The Blob is tipically used as a resource for write operations that require and OuputStream but can also be filled directly using setContent.

Copy
<script>
    var blob = new Ax.sql.Blob("data.txt");
    blob.setContentType("text/plain");
    blob.setContent("Hello World");
    blob.setContent(`
This is a sample text
using template string
    `);
    
    console.log("BLOB NAME   =" + blob.getFileName());
    console.log("TEXT CONTENT=" + blob.getTextContent());
    return blob;
</script>
BLOB NAME =data.txt 
TEXT CONTENT=Hello World
This is a sample text
using template string
void setContent(byte[] data) Set contents of blob
void setContent(String text) Set contents of blob using text. UTF-8 encoding will be used for the conversion to bytes
void setContent(String text, String charsetName) Set contents of blob using text using provided charset encoding
void setDisposition(String disposition) Set file disposition
boolean isInline() Is inline getter
boolean isAttachment() Is attachment getter
byte[] getContent() Get byte contents of blob
String getTextContent() Get contents of blob as text. UTF-8 encoding will be used for the conversion from bytes
String getTextContent(String charsetName) Get contents of blob as text using the provided charset encoding
void writeTo(JSFile file) Wtite blob contents to provided file

1.1 Blobs from database

During SQL operations you can get get or write blob objects. For example, to write and read a blob from database simply do:

Copy
<script>
	var blob = new Ax.sql.Blob("data.txt");
    blob.setContentType("text/plain");
    blob.setContent(`
This is a sample text
using template string
    `);

    Ax.db.execute("DROP TABLE IF EXISTS test_blob");
    Ax.db.execute("CREATE TABLE IF NOT EXISTS test_blob(a integer, b blob)");
  	Ax.db.insert("test_blob", {
  		"a" : 1,
  		"b" : blob
  	});

  	var data = Ax.db.executeQuery("SELECT * FROM test_blob").toOne();
  	console.log(data.b);
</script>
00000000 0A 54 68 69 73 20 69 73 20 61 20 73 61 6D 70 6C .This is a sampl
00000010 65 20 74 65 78 74 0A 75 73 69 6E 67 20 74 65 6D e text.using tem
00000020 70 6C 61 74 65 20 73 74 72 69 6E 67 0A 20 20 20 plate string.   
00000030 20

1.2 Write and read strings from blob

Create a blob and write a string to it. The encoding parameter is optional and defaults to UTF-8

Copy
<script>
	var blob = new Ax.sql.Blob("data.txt");
    blob.setContentType("text/plain");
    blob.setContent(" àèáéòóìí ", "iso-8859-1"); //  blob.setContent(text) uses UTF-8

    // unreadable characters (using UTF-8)
    console.log(blob.getTextContent());

    // ok
    console.log(blob.getTextContent("iso-8859-1"));

</script>
�������� 
 àèáéòóìí

1.3 Blobs from file

Another class constructor allows to pass a file object (Ax.io.File) and this blob class will read file content and store it in memory.

Copy
<script>
    var blob = new Ax.sql.Blob(new Ax.io.File("/etc/hosts"));
    return blob;
</script>
127.0.0.1 localhost

1.4 Blobs from resultset

Another class constructor allows to pass a byte Array and this blob class will create a Blob object with data and store it in memory.

Copy
<script>
var rrs = new Ax.rs.Reader().db(options => {
    options.setResultSet(Ax.db.executeQuery("SELECT * FROM test_blob"));
}).cols().add("MIMETYPE", Ax.sql.Types.CHAR, v => {
    
    return new Ax.sql.Blob(v.getBytes("file_data")).getContentType();
}).cols().drop("file_data");

console.log(rrs);
</script>
127.0.0.1 localhost

1.5 Publishing blobs

A common problem is how to expose blob content stored in database or filesystem to web site. To solve that, simply select the blob object and get a URL reference.

Copy
<script>
	var blob = new Ax.sql.Blob("data.txt");
    blob.setContentType("text/plain");
    blob.setContent("Hello World");
    blob.setContent(`
This is a sample text
using template string
    `);
    console.log(blob.toMemoryURL());
    </script>
blob://localhost/def4a32f-995a-4172-99e3-b7e9dd7661c1

2 Api

Class Ax.sql.Blob


This objects are DataTypes. Don't extend AbstractScriptClass In memory blob holder

Constructor Summary

MethodDescription
JSBlob()
JSBlob(String name)Create a blob holder for given file name
JSBlob(byte[] data)Create a blob holder for given file name, type and data
JSBlob(String name, byte[] data)Create a blob holder for given file name, type and data
JSBlob(String name, byte[] data, String type)Create a blob holder for given file name, type and data
JSBlob(JSFile file)Create a blob holder for given file name and transfer data from file to blob TODO: keep a ref to file.

Method Summary

Modifier and TypeMethodDescription
void close(String arg0)
void free()
InputStream getBinaryStream()
InputStream getBinaryStream(long arg0, long arg1)
byte[] getBytes()
byte[] getBytes(long arg0, int arg1)
byte[] getContent()
String getContentID()
String getContentType()
String getDisposition()
String getFileName()
long getLength()
int getLimit(Object arg0)
getMetaData()
OutputStream getOutputStream()
long getRowId()
long getSeqNo()
String getStore()
String getText()
String getTextContent()
String getTextContent(String charsetName)
String getUUID()
long getVTableRowAccessAge()
long getVTableRowAccessCount()
long getVTableRowAccessTime()
long getVTableRowBuildTime()
long getVTableRowCreatedAge()
boolean hasContentType()
boolean isAttachment()
boolean isCloseable()
boolean isInline()
boolean isLocked()
boolean isOneUse()
boolean isShared()
long length()
void lock()
long position(byte[] arg0, long arg1)
long position(Blob arg0, long arg1)
OutputStream setBinaryStream(long arg0)
OutputStream setBinaryStream(long arg0)
int setBytes(long arg0, byte[] arg1)
int setBytes(long arg0, byte[] arg1, int arg2, int arg3)
JSBlob setContent(byte[] data)Adds the byte[] provided to blob content
JSBlob setContent(String text)Adds the text as UTF8 bytes to blob content
JSBlob setContent(String text, String charsetName)Adds the text as UTF8 bytes to blob content
JSBlob setContentID(String contentID)When using BLOBs to read Mail parts we can check for its contentID
void setContentType(String arg0)
JSBlob setDisposition(String disposition)When using BLOBs to read Mail parts we can check for its content disposition
void setFileName(String arg0)
void setOneUse()
void setSeqNo(int arg0)
void setShared()
void setVTableRowAccessCount()
void setVTableRowAccessTime()
String toBase64()
String toMemoryURL()Return a internal memory URL to the blob.
String toString()
VTable toVTable()
Object[] toVTableRow()
void truncate(long arg0)
boolean tryLock(int arg0, TimeUnit arg1)
void unlock()
Path writeTo(JSFile file)
Path writeTo(File arg0)

Method Detail

JSBlob

 JSBlob()

JSBlob

 JSBlob(String name)
Info:
Create a blob holder for given file name
Parameters:
name - 

JSBlob

 JSBlob(byte[] data)
Info:
Create a blob holder for given file name, type and data
Parameters:
data - 

JSBlob

 JSBlob(String name, byte[] data)
Info:
Create a blob holder for given file name, type and data
Parameters:
name - 
data - 

JSBlob

 JSBlob(String name, byte[] data, String type)
Info:
Create a blob holder for given file name, type and data
Parameters:
name - 
data - 
type - 

JSBlob

 JSBlob(JSFile file)
Info:
Create a blob holder for given file name and transfer data from file to blob TODO: keep a ref to file... TODO: keep a ref to file... TODO: keep a ref to file... TODO: keep a ref to file... TODO: keep a ref to file...
Parameters:
file - 

close

void close(String arg0)
Parameters:
arg0 - 

free

void free()

getBinaryStream

                        InputStream getBinaryStream()
Returns:

getBinaryStream

                        InputStream getBinaryStream(long arg0, long arg1)
Parameters:
arg0 - 
arg1 - 
Returns:

getBytes

byte[] getBytes()
Returns:

getBytes

byte[] getBytes(long arg0, int arg1)
Parameters:
arg0 - 
arg1 - 
Returns:

getContent

byte[] getContent()
Returns:

getContentID

                        String getContentID()
Returns:

getContentType

                        String getContentType()
Returns:

getDisposition

                        String getDisposition()
Returns:

getFileName

                        String getFileName()
Returns:

getLength

long getLength()
Returns:

getLimit

int getLimit(Object arg0)
Parameters:
arg0 - 
Returns:

getMetaData

K getMetaData()
Returns:

getOutputStream

                        OutputStream getOutputStream()
Returns:

getRowId

long getRowId()
Returns:

getSeqNo

long getSeqNo()
Returns:

getStore

                        String getStore()
Returns:

getText

                        String getText()
Returns:

getTextContent

                        String getTextContent()
Returns:

getTextContent

                        String getTextContent(String charsetName)
Parameters:
charsetName - 
Returns:

getUUID

                        String getUUID()
Returns:

getVTableRowAccessAge

long getVTableRowAccessAge()
Returns:

getVTableRowAccessCount

long getVTableRowAccessCount()
Returns:

getVTableRowAccessTime

long getVTableRowAccessTime()
Returns:

getVTableRowBuildTime

long getVTableRowBuildTime()
Returns:

getVTableRowCreatedAge

long getVTableRowCreatedAge()
Returns:

hasContentType

boolean hasContentType()
Returns:

isAttachment

boolean isAttachment()
Returns:

isCloseable

boolean isCloseable()
Returns:

isInline

boolean isInline()
Returns:

isLocked

boolean isLocked()
Returns:

isOneUse

boolean isOneUse()
Returns:

isShared

boolean isShared()
Returns:

length

long length()
Returns:

lock

void lock()

position

long position(byte[] arg0, long arg1)
Parameters:
arg0 - 
arg1 - 
Returns:

position

long position(Blob arg0, long arg1)
Parameters:
arg0 - 
arg1 - 
Returns:

setBinaryStream

                        OutputStream setBinaryStream(long arg0)
Parameters:
arg0 - 
Returns:

setBinaryStream

                        OutputStream setBinaryStream(long arg0)
Parameters:
arg0 - 
Returns:

setBytes

int setBytes(long arg0, byte[] arg1)
Parameters:
arg0 - 
arg1 - 
Returns:

setBytes

int setBytes(long arg0, byte[] arg1, int arg2, int arg3)
Parameters:
arg0 - 
arg1 - 
arg2 - 
arg3 - 
Returns:

setContent

                        JSBlob setContent(byte[] data)
Info:
Adds the byte[] provided to blob content
Parameters:
data - 
Returns:

setContent

                        JSBlob setContent(String text)
Info:
Adds the text as UTF8 bytes to blob content
Parameters:
text - 
Returns:

setContent

                        JSBlob setContent(String text, String charsetName)
Info:
Adds the text as UTF8 bytes to blob content
Parameters:
text - 
charsetName - 
Returns:

setContentID

                        JSBlob setContentID(String contentID)
Info:
When using BLOBs to read Mail parts we can check for its contentID
Parameters:
contentID - 
Returns:

setContentType

void setContentType(String arg0)
Parameters:
arg0 - 

setDisposition

                        JSBlob setDisposition(String disposition)
Info:
When using BLOBs to read Mail parts we can check for its content disposition
Parameters:
disposition - 
Returns:

setFileName

void setFileName(String arg0)
Parameters:
arg0 - 

setOneUse

void setOneUse()

setSeqNo

void setSeqNo(int arg0)
Parameters:
arg0 - 

setShared

void setShared()

setVTableRowAccessCount

void setVTableRowAccessCount()

setVTableRowAccessTime

void setVTableRowAccessTime()

toBase64

                        String toBase64()
Returns:

toMemoryURL

                        String toMemoryURL()
Info:
Return a internal memory URL to the blob. It can be used for internal applications like "internal" apps like FOP, barcode, etc that need to access a blob without going to http
Returns:

toString

                        String toString()
Returns:

toVTable

                        VTable toVTable()
Returns:

toVTableRow

                        Object[] toVTableRow()
Returns:

truncate

void truncate(long arg0)
Parameters:
arg0 - 

tryLock

boolean tryLock(int arg0, TimeUnit arg1)
Parameters:
arg0 - 
arg1 - 
Returns:

unlock

void unlock()

writeTo

                        Path writeTo(JSFile file)
Parameters:
file - 
Returns:

writeTo

                        Path writeTo(File arg0)
Parameters:
arg0 - 
Returns: