protected OrientBlob(List<OBlob> binaryDataChunks) throws IllegalArgumentException { this.binaryDataChunks = new ArrayList<>(binaryDataChunks.size()); for (OBlob binaryDataChunk : binaryDataChunks) { if (binaryDataChunk == null) { throw new IllegalArgumentException("The binary data chunks list cannot hold null chunks"); } else if (binaryDataChunk.getSize() == 0) { throw new IllegalArgumentException("The binary data chunks list cannot hold empty chunks"); } else { this.binaryDataChunks.add(binaryDataChunk.toStream()); } } this.length = calculateLength(); }
@Override public ORecord fromStream(final byte[] iSource, final ORecord iRecord, String[] iFields) { final OBlob record = (OBlob) iRecord; record.reset(); record.fromStream(iSource); return record; }
public byte[] getBytes(String columnLabel) throws SQLException { try { Object value = result.getProperty(columnLabel); if (value == null) { lastReadWasNull = true; return null; } else { if (value instanceof OBlob) { lastReadWasNull = false; return ((OBlob) value).toStream(); } byte[] r = result.getProperty(columnLabel); lastReadWasNull = r == null; return r; } } catch (Exception e) { throw new SQLException("An error occurred during the retrieval of the bytes value at column '" + columnLabel + "'", e); } }
OBlob rec = (OBlob) currentRecord; message("\n+-------------------------------------------------------------------------------------------------+"); message("\n| Bytes - @rid: %s @version: %d", rec.getIdentity().toString(), rec.getVersion()); message("\n+-------------------------------------------------------------------------------------------------+"); final byte[] value = rec.toStream(); final int max = Math.min(Integer.parseInt(properties.get("maxBinaryDisplay")), Array.getLength(value)); for (int i = 0; i < max; ++i) {
private Object getFieldValue(final int iIndex, final OIdentifiable iRecord, final String iColumnName) { Object value = null; if (iColumnName.equals("#")) // RECORD NUMBER value = iIndex > -1 ? iIndex : ""; else if (iColumnName.equals("@RID")) // RID value = iRecord.getIdentity().toString(); else if (iRecord instanceof ODocument) value = ((ODocument) iRecord).getProperty(iColumnName); else if (iRecord instanceof OBlob) value = "<binary> (size=" + ((OBlob) iRecord).toStream().length + " bytes)"; else if (iRecord instanceof OIdentifiable) { final ORecord rec = iRecord.getRecord(); if (rec instanceof ODocument) value = ((ODocument) rec).getProperty(iColumnName); else if (rec instanceof OBlob) value = "<binary> (size=" + ((OBlob) rec).toStream().length + " bytes)"; } return getPrettyFieldValue(value, maxMultiValueEntries); }
public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { final Object candidate = iParams[0]; final String format = iParams[1].toString(); byte[] data = null; if (candidate instanceof byte[]) { data = (byte[]) candidate; } else if (candidate instanceof ORecordId) { final ORecord rec = ((ORecordId) candidate).getRecord(); if (rec instanceof OBlob) { data = ((OBlob) rec).toStream(); } } else if (candidate instanceof OSerializableStream) { data = ((OSerializableStream) candidate).toStream(); } if (data == null) { return null; } if (FORMAT_BASE64.equalsIgnoreCase(format)) { return Base64.getEncoder().encodeToString(data); } else { throw new ODatabaseException("unknowned format :" + format); } }
json.writeAttribute(settings.indentLevel, true, "value", Base64.getEncoder().encodeToString(record.toStream())); } else