use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class Account method toStream.
@OBeforeSerialization
public void toStream(final ODocument iDocument) {
if (thumbnail != null) {
// WRITE THE PHOTO IN AN EXTERNAL RECORD AS PURE BINARY
OBlob externalPhoto = new ORecordBytes(thumbnail);
iDocument.field("externalPhoto", externalPhoto);
}
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class LocalDocumentAndBinarySpeedTest method loadRandomMixed.
@Test(dependsOnMethods = "saveLotOfMixedData")
public void loadRandomMixed() {
database.open(DEFAULT_DB_USER, DEFAULT_DB_PASSWORD);
index = database.getMetadata().getSchema().getClass("Chunk").getProperty("hash").getIndexes().iterator().next();
Assert.assertNotNull(index);
Set<Integer> alreadyLoaded = new HashSet<Integer>();
try {
for (int i = 0; i < load; i++) {
int rand = (int) (Math.random() * count);
if (!alreadyLoaded.contains(rand))
alreadyLoaded.add(rand);
else
System.out.println("already loaded");
OIdentifiable result = (OIdentifiable) index.get("key" + Integer.toString(rand));
Assert.assertNotNull(result);
ODocument doc = (ODocument) result.getRecord();
System.out.println("loaded " + i + "(" + rand + "), binary record: " + doc.field("binary", ORID.class));
OBlob record = doc.field("binary");
Assert.assertNotNull(record);
if (record != null) {
byte[] data = record.toStream();
Assert.assertTrue(data.length == size);
}
if (i % 100 == 0)
System.out.println("loaded " + i);
}
} finally {
database.close();
}
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class OConsoleDatabaseApp method dumpRecordDetails.
private void dumpRecordDetails() {
if (currentRecord == null)
return;
else if (currentRecord instanceof ODocument) {
ODocument rec = (ODocument) currentRecord;
if (rec.getClassName() != null || rec.getIdentity().isValid()) {
message("\nDOCUMENT @class:%s @rid:%s @version:%d", rec.getClassName(), rec.getIdentity().toString(), rec.getVersion());
}
final List<ODocument> resultSet = new ArrayList<ODocument>();
Object value;
for (String fieldName : rec.fieldNames()) {
value = rec.field(fieldName);
if (value instanceof byte[])
value = "byte[" + ((byte[]) value).length + "]";
else if (value instanceof Iterator<?>) {
final List<Object> coll = new ArrayList<Object>();
while (((Iterator<?>) value).hasNext()) coll.add(((Iterator<?>) value).next());
value = coll;
} else if (OMultiValue.isMultiValue(value)) {
value = OTableFormatter.getPrettyFieldMultiValue(OMultiValue.getMultiValueIterator(value), getMaxMultiValueEntries());
}
final ODocument row = new ODocument();
resultSet.add(row);
row.field("NAME", fieldName);
row.field("VALUE", value);
}
final OTableFormatter formatter = new OTableFormatter(this);
formatter.writeRecords(resultSet, -1);
} else if (currentRecord instanceof OBlob) {
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) {
message("%03d", Array.getByte(value, i));
}
message("\n+-------------------------------------------------------------------------------------------------+");
} else {
message("\n+-------------------------------------------------------------------------------------------------+");
message("\n| %s - record id: %s v.%d", currentRecord.getClass().getSimpleName(), currentRecord.getIdentity().toString(), currentRecord.getVersion());
message("\n+-------------------------------------------------------------------------------------------------+");
}
out.println();
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class BinaryTest method testBasicReadExternal.
@Test(dependsOnMethods = "testBasicCreateExternal")
public void testBasicReadExternal() {
OBlob record = database.load(rid);
Assert.assertEquals("This is a test", new String(record.toStream()));
}
use of com.orientechnologies.orient.core.record.impl.OBlob in project orientdb by orientechnologies.
the class BinaryTest method testMixedReadExternal.
@Test(dependsOnMethods = "testMixedCreateExternal")
public void testMixedReadExternal() {
ODocument doc = new ODocument(rid);
doc.reload();
Assert.assertEquals("Binary data", new String(((OBlob) doc.field("binary")).toStream()));
}
Aggregations