Example usage for java.sql Blob free

List of usage examples for java.sql Blob free

Introduction

In this page you can find the example usage for java.sql Blob free.

Prototype

void free() throws SQLException;

Source Link

Document

This method frees the Blob object and releases the resources that it holds.

Usage

From source file:org.zanata.liquibase.custom.MigrateRawDocumentsToFileSystem.java

private void writeBlobToFile(Blob content, String fileName) throws SQLException, IOException {
    File outputFile = createFileInConfiguredDirectory(fileName);
    writeStreamToFile(content.getBinaryStream(), outputFile);
    // releasing blob resources may not be necessary, but makes me feel
    // better and shouldn't cause problems
    content.free();
    content = null;//w  w w  .j av  a2 s  .c  om
}

From source file:org.zaproxy.zap.extension.websocket.db.TableWebSocket.java

/**
 * @param rs//  w ww  .  jav  a  2  s. co m
 * @param interpretLiteralBytes
 * @param payloadLength
 * @return
 * @throws HttpMalformedHeaderException
 * @throws SQLException
 * @throws DatabaseException
 */
private List<WebSocketMessageDTO> buildMessageDTOs(ResultSet rs, boolean interpretLiteralBytes,
        int payloadLength) throws SQLException, DatabaseException {
    ArrayList<WebSocketMessageDTO> messages = new ArrayList<>();
    try {
        while (rs.next()) {
            WebSocketMessageDTO message;

            int channelId = rs.getInt("channel_id");
            WebSocketChannelDTO channel = getChannel(channelId);

            if (rs.getInt("fuzz_id") != 0) {
                WebSocketFuzzMessageDTO fuzzMessage = new WebSocketFuzzMessageDTO(channel);
                fuzzMessage.fuzzId = rs.getInt("fuzz_id");
                fuzzMessage.state = WebSocketFuzzMessageDTO.State.valueOf(rs.getString("state"));
                fuzzMessage.fuzz = rs.getString("fuzz");

                message = fuzzMessage;
            } else {
                message = new WebSocketMessageDTO(channel);
            }

            message.id = rs.getInt("message_id");
            message.setTime(rs.getTimestamp("timestamp"));
            message.opcode = rs.getInt("opcode");
            message.readableOpcode = WebSocketMessage.opcode2string(message.opcode);

            // read payload
            if (message.opcode == WebSocketMessage.OPCODE_BINARY) {
                if (payloadLength == -1) {
                    // load all bytes
                    message.payload = rs.getBytes("payload_bytes");
                } else {
                    Blob blob = rs.getBlob("payload_bytes");
                    int length = Math.min(payloadLength, (int) blob.length());
                    message.payload = blob.getBytes(1, length);
                    blob.free();
                }

                if (message.payload == null) {
                    message.payload = new byte[0];
                }
            } else {
                if (payloadLength == -1) {
                    // load all characters
                    message.payload = rs.getString("payload_utf8");
                } else {
                    Clob clob = rs.getClob("payload_utf8");
                    int length = Math.min(payloadLength, (int) clob.length());
                    message.payload = clob.getSubString(1, length);
                    clob.free();
                }

                if (message.payload == null) {
                    message.payload = "";
                }
            }

            message.isOutgoing = rs.getBoolean("is_outgoing");
            message.payloadLength = rs.getInt("payload_length");

            messages.add(message);
        }
    } finally {
        rs.close();
    }

    messages.trimToSize();

    return messages;
}

From source file:procuradoria.pdf.util.DocumentsPdf.java

public static void byteArrayToFile(Uzatdocs doc) {
    try {//www  .  java 2s .  c o m
        Blob blob = doc.getUzatdocsArchivo();

        int blobLength = (int) blob.length();
        byte[] bArray = blob.getBytes(1, blobLength);
        blob.free();
        OutputStream out = new FileOutputStream("out.pdf");
        out.write(bArray);
        out.close();
    } catch (Exception ex) {
        log.level.info(">> Exception " + ex.getMessage());
    }
}