/** * @see IBlobReader#disposeBlob() */ public void disposeBlob() { _blob.dispose(); }
/** * @see IBlobReader#getBlobSize() */ public int getBlobSize() { try { return _blob.getSize(); } catch (SQLiteException e) { logger.error("can't get SQLiteBlob size",e); return 0; } }
private int _getIntFromBlob( final SQLiteBlob blob, final int idx ) { final byte[] byteBuffer = new byte[4]; try { blob.read(idx, byteBuffer, 0, 4); } catch (SQLiteException e) { logger.error("can't read bytes from the SQLiteBlob",e); } // read 4 bytes return BytesUtils.bytesToInt(byteBuffer, 0); }
private void finalizeBlob(SQLiteBlob blob) { Internal.logFine(blob, "finalizing"); SWIGTYPE_p_sqlite3_blob handle = blob.blobHandle(); blob.clear(); softClose(handle, blob); synchronized (myLock) { forgetBlob(blob); } }
/** * Returns the size of the open blob. The size cannot be changed via this interface. * * @return size of the blobs in bytes * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class */ public int getSize() throws SQLiteException { myController.validate(); if (myLength < 0) { myLength = _SQLiteSwigged.sqlite3_blob_bytes(handle()); } return myLength; }
/** * Disposes this blob and frees allocated resources. * <p> * After blob is disposed, it is no longer usable and holds no references to connection * or sqlite db. */ public void dispose() { if (myHandle == null) return; try { myController.validate(); } catch (SQLiteException e) { Internal.recoverableError(this, "invalid dispose: " + e, true); return; } Internal.logFine(this, "disposing"); myController.dispose(this); // clear may be called from dispose() too clear(); }
result = new SQLiteBlob(myUncachedController, blob, dbname, table, column, rowid, writeAccess); myBlobs.add(result); } else {
/** * Read bytes from the blob into a buffer. * <p> * <code>blobOffset</code> and <code>length</code> should define a sub-range within blob's content. If attempt is * made to read blob beyond its size, an exception is thrown and no data is read. * * @param blobOffset the position in the blob where to start reading * @param buffer target buffer * @param offset starting offset in the buffer * @param length number of bytes to read * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class * @see <a href="http://www.sqlite.org/c3ref/blob_read.html">sqlite3_blob_read</a> */ public void read(int blobOffset, byte[] buffer, int offset, int length) throws SQLiteException { if (buffer == null) throw new NullPointerException(); if (offset < 0 || offset + length > buffer.length) throw new ArrayIndexOutOfBoundsException(buffer.length + " " + offset + " " + length); myController.validate(); if (Internal.isFineLogging()) Internal.logFine(this, "read[" + blobOffset + "," + length + "]"); int rc = _SQLiteManual.sqlite3_blob_read(handle(), blobOffset, buffer, offset, length); myController.throwResult(rc, "read", this); }
private int _getIntFromBlob( final SQLiteBlob blob, final int idx ) { final byte[] byteBuffer = new byte[4]; try { blob.read(idx, byteBuffer, 0, 4); } catch (SQLiteException e) { logger.error("can't read bytes from the SQLiteBlob",e); } // read 4 bytes return BytesUtils.bytesToInt(byteBuffer, 0); }
/** * Writes bytes into the blob. Bytes are taken from the specified range in the input byte buffer. * <p> * Note that you cannot write beyond the current blob's size. The size of the blob * cannot be changed via incremental I/O API. To change the size, you need to use {@link SQLiteStatement#bindZeroBlob} * method. * <p> * Bytes are written within the current transaction. * <p> * If blob was not open for writing, an error is thrown. * * @param blobOffset the position in the blob where to start writing * @param buffer source bytes buffer * @param offset starting offset in the buffer * @param length number of bytes to write * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class * @see <a href="http://www.sqlite.org/c3ref/blob_write.html">sqlite3_blob_write</a> */ public void write(int blobOffset, byte[] buffer, int offset, int length) throws SQLiteException { if (buffer == null) throw new NullPointerException(); if (offset < 0 || offset + length > buffer.length) throw new ArrayIndexOutOfBoundsException(buffer.length + " " + offset + " " + length); myController.validate(); if (Internal.isFineLogging()) Internal.logFine(this, "write[" + blobOffset + "," + length + "]"); int rc = _SQLiteManual.sqlite3_blob_write(handle(), blobOffset, buffer, offset, length); myController.throwResult(rc, "write", this); }
/** * @see IBlobReader#disposeBlob() */ public void disposeBlob() { _blob.dispose(); }
/** * @see IBlobReader#getBlobSize() */ public int getBlobSize() { try { return _blob.getSize(); } catch (SQLiteException e) { logger.error("can't get SQLiteBlob size",e); return 0; } }
/** * @see IBlobReader#spectrumSliceOfSpectrumAt(int) */ // TODO: factorize this code with the one from BytesReader private SpectrumData _readFilteredSpectrumSliceDataAt(final int idx, final long spectrumId, final double minMz, final double maxMz) { // Determine peak size in bytes final DataEncoding de = this._dataEncodingBySpectrumId.get(spectrumId); // Determine peaks bytes length final int peaksBytesSize = _peaksCounts[idx] * de.getPeakStructSize(); // Skip spectrum id and peaks count (two integers) final int spectrumSliceStartPos = _spectrumSliceStartPositions[idx] + 8; final byte[] peaksBytes = new byte[peaksBytesSize]; try { _blob.read(spectrumSliceStartPos, peaksBytes, 0, peaksBytesSize); } catch (SQLiteException e) { logger.error("can't read bytes from the SQLiteBlob",e); } // Instantiate a new SpectrumData for the corresponding spectrum slice return this.readSpectrumSliceData( ByteBuffer.wrap(peaksBytes), spectrumSliceStartPos, peaksBytesSize, de, minMz, maxMz ); }
/** * Repositions BLOB to another row in the table. It should be quickier that closing the blob and opening another one. * * @param rowid row id to move to - it must exist and contain data * @throws SQLiteException if SQLite returns an error, or if the call violates the contract of this class * @see <a href="http://www.sqlite.org/c3ref/blob_reopen.html">sqlite3_blob_reopen</a> */ public void reopen(long rowid) throws SQLiteException { myController.validate(); if (Internal.isFineLogging()) Internal.logFine(this, "reopen[" + rowid + "]"); int rc = _SQLiteSwigged.sqlite3_blob_reopen(handle(), rowid); myController.throwResult(rc, "reopen", this); }
/** * @see IBlobReader#spectrumSliceOfSpectrumAt(int) */ // TODO: factorize this code with the one from BytesReader private SpectrumData _readFilteredSpectrumSliceDataAt(final int idx, final long spectrumId, final double minMz, final double maxMz) { // Determine peak size in bytes final DataEncoding de = this._dataEncodingBySpectrumId.get(spectrumId); // Determine peaks bytes length final int peaksBytesSize = _peaksCounts[idx] * de.getPeakStructSize(); // Skip spectrum id and peaks count (two integers) final int spectrumSliceStartPos = _spectrumSliceStartPositions[idx] + 8; final byte[] peaksBytes = new byte[peaksBytesSize]; try { _blob.read(spectrumSliceStartPos, peaksBytes, 0, peaksBytesSize); } catch (SQLiteException e) { logger.error("can't read bytes from the SQLiteBlob",e); } // Instantiate a new SpectrumData for the corresponding spectrum slice return this.readSpectrumSliceData( ByteBuffer.wrap(peaksBytes), spectrumSliceStartPos, peaksBytesSize, de, minMz, maxMz ); }