BBjspObjectSerializer


 

Description

In BBj 16.0 and higher, this class comes as part of the BBJSP framework and provides a set of static utility methods for encoding and decoding objects and files. You can, for example, use these methods to encode images or other files for storage in a database.

Methods of BBjspObjectSerializer

Return Value

Method

Object

decodeObject(string base64)

void

decodeToStream(string base64, OutputStream stream)

string

encodeObject(Object object)

string

encodeStream(InputStream stream)

boolean

isSerializable(Object object)

Example

REM ===
REM === This Servlet extracts an image from a database and sends the result back to the client browser
REM ===

class public GetImage

  method public void service(BBjspServletContext context!)
      declare BBjspWebRequest request!
      declare BBjspWebResponse response!
      
      db$ = context!.getParameter("DATABASE")

      request! = context!.getRequest()
      response! = context!.getResponse()
      
      sql$ = "SELECT * FROM IMAGES WHERE IMAGE_ID=?"

      ch=sqlunt
      sqlopen (ch)db$
      sqlprep (ch)sql$
      sqlexec (ch)request!.getParameter("image_id")

      dim x$:sqltmpl(ch)
      x$=sqlfetch(ch,ERR=NO_IMAGE)

      img$ = x.IMAGE_DATA$
      response!.setContentType("image/png")

      BBjspObjectSerializer.decodeToStream(img$,response!.getOutputStream())
NO_IMAGE:
      sqlclose(ch)
  methodend
    
classend

See Also

BBJSP