Ejemplo n.º 1
0
  private void handleLobResult(String charSet, Object result, ServiceResponse response)
      throws SQLException {
    if (result == null) {
      return; // or should this be an empty result?
    }

    if (result instanceof SQLXML) {
      if (charSet != null) {
        XMLSerialize serialize = new XMLSerialize();
        serialize.setTypeString("blob"); // $NON-NLS-1$
        serialize.setDeclaration(true);
        serialize.setEncoding(charSet);
        serialize.setDocument(true);
        try {
          InputStream content =
              ((BlobType) XMLSystemFunctions.serialize(serialize, new XMLType((SQLXML) result)))
                  .getBinaryStream();
          response.writeContent(content, 200, false);
          response.writeOK(ContentType.APPLICATION_OCTET_STREAM);
        } catch (TransformationException e) {
          throw new SQLException(e);
        }
      } else {
        InputStream content = ((SQLXML) result).getBinaryStream();
        response.writeContent(content, 200, false);
        response.writeOK(ContentType.APPLICATION_XML);
      }
    } else if (result instanceof Blob) {
      InputStream content = ((Blob) result).getBinaryStream();
      response.writeContent(content, 200, false);
      response.writeOK(ContentType.APPLICATION_OCTET_STREAM);
    } else if (result instanceof Clob) {
      InputStream content =
          new ReaderInputStream(
              ((Clob) result).getCharacterStream(),
              charSet == null ? Charset.defaultCharset() : Charset.forName(charSet));
      response.writeContent(content, 200, false);
      response.writeOK(ContentType.TEXT_PLAIN);
    } else {
      InputStream content =
          new ByteArrayInputStream(
              result
                  .toString()
                  .getBytes(charSet == null ? Charset.defaultCharset() : Charset.forName(charSet)));
      response.writeContent(content, 200, false);
      response.writeOK(ContentType.APPLICATION_OCTET_STREAM);
    }
  }
 @Override
 public void visit(XMLSerialize obj) {
   preVisitVisitor(obj);
   visitNode(obj.getExpression());
   postVisitVisitor(obj);
 }