org.apache.jackrabbit.core.data.DataStore.addRecord()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中org.apache.jackrabbit.core.data.DataStore.addRecord()方法的一些代码示例,展示了DataStore.addRecord()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataStore.addRecord()方法的具体详情如下:
包路径:org.apache.jackrabbit.core.data.DataStore
类名称:DataStore
方法名:addRecord

DataStore.addRecord介绍

[英]Creates a new data record. The given binary stream is consumed and a binary record containing the consumed stream is created and returned. If the same stream already exists in another record, then that record is returned instead of creating a new one.

The given stream is consumed and not closed by this method. It is the responsibility of the caller to close the stream. A typical call pattern would be:

InputStream stream = ...; 
try { 
record = store.addRecord(stream); 
} finally { 
stream.close(); 
}

[中]创建新的数据记录。将使用给定的二进制流,并创建并返回包含所使用流的二进制记录。如果相同的流已经存在于另一条记录中,则返回该记录,而不是创建新记录。
给定的流被此方法消耗而不是关闭。调用方负责关闭流。典型的呼叫模式是:

InputStream stream = ...; 
try { 
record = store.addRecord(stream); 
} finally { 
stream.close(); 
}

代码示例

代码示例来源:origin: org.apache.jackrabbit/oak-blob-plugins

@Override
public DataRecord addRecord(InputStream input, BlobOptions options) throws DataStoreException {
  if (delegate instanceof TypedDataStore) {
    return ((TypedDataStore) delegate).addRecord(input, options);
  }
  return delegate.addRecord(input);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Override
public DataRecord addRecord(InputStream input, BlobOptions options) throws DataStoreException {
  if (delegate instanceof TypedDataStore) {
    return ((TypedDataStore) delegate).addRecord(input, options);
  }
  return delegate.addRecord(input);
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public DataRecord addRecord(InputStream input, BlobOptions options) throws DataStoreException {
  if (delegate instanceof TypedDataStore) {
    return ((TypedDataStore) delegate).addRecord(input, options);
  }
  return delegate.addRecord(input);
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-core

static BLOBInDataStore getInstance(DataStore store, InputStream in) throws DataStoreException {
  DataRecord rec = store.addRecord(in);
  DataIdentifier identifier = rec.getIdentifier();
  if (auditLogger.isDebugEnabled()) {
    auditLogger.debug("{} ({})", identifier, rec.getLength());
  }
  return new BLOBInDataStore(store, identifier);
}

代码示例来源:origin: apache/jackrabbit

static BLOBInDataStore getInstance(DataStore store, InputStream in) throws DataStoreException {
  DataRecord rec = store.addRecord(in);
  DataIdentifier identifier = rec.getIdentifier();
  if (auditLogger.isDebugEnabled()) {
    auditLogger.debug("{} ({})", identifier, rec.getLength());
  }
  return new BLOBInDataStore(store, identifier);
}

代码示例来源:origin: org.apache.jackrabbit/oak-upgrade

@Override
public DataRecord addRecord(InputStream inputStream) throws DataStoreException {
  checkIfReadOnly();
  DataRecord result = getDelegate().addRecord(inputStream);
  addNewMapping(result);
  return result;
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public DataRecord addRecord(InputStream inputStream) throws DataStoreException {
  checkIfReadOnly();
  DataRecord result = getDelegate().addRecord(inputStream);
  addNewMapping(result);
  return result;
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Test if record can be accessed via
 * {@link DataStore#getRecordFromReference(String)}
 */
protected void doReferenceTest() throws Exception {
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  String reference;
  DataRecord record = ds.addRecord(new ByteArrayInputStream(data));
  reference = record.getReference();
  assertReference(data, reference, ds);
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Test {@link DataStore#addRecord(InputStream)} and assert length of added
 * record.
 */
protected void doAddRecordTest() throws Exception {
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  Assert.assertEquals(data.length, rec.getLength());
  assertRecord(data, rec);
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Test {@link DataStore#getAllIdentifiers()} and asserts all identifiers
 * are returned.
 */
protected void doGetAllIdentifiersTest() throws Exception {
  List<DataIdentifier> list = new ArrayList<DataIdentifier>();
  Random random = randomGen;
  byte[] data = new byte[dataLength];
  random.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  list.add(rec.getIdentifier());
  data = new byte[dataLength];
  random.nextBytes(data);
  rec = ds.addRecord(new ByteArrayInputStream(data));
  list.add(rec.getIdentifier());
  data = new byte[dataLength];
  random.nextBytes(data);
  rec = ds.addRecord(new ByteArrayInputStream(data));
  list.add(rec.getIdentifier());
  Iterator<DataIdentifier> itr = Sets.newHashSet(ds.getAllIdentifiers()).iterator();
  while (itr.hasNext()) {
    assertTrue("record found on list", list.remove(itr.next()));
  }
  Assert.assertEquals(0, list.size());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link DataStore#getAllIdentifiers()} and asserts all identifiers
 * are returned.
 */
protected void doGetAllIdentifiersTest() throws Exception {
  ds = createDataStore();
  List<DataIdentifier> list = new ArrayList<DataIdentifier>();
  Random random = randomGen;
  byte[] data = new byte[dataLength];
  random.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  list.add(rec.getIdentifier());
  data = new byte[dataLength];
  random.nextBytes(data);
  rec = ds.addRecord(new ByteArrayInputStream(data));
  list.add(rec.getIdentifier());
  data = new byte[dataLength];
  random.nextBytes(data);
  rec = ds.addRecord(new ByteArrayInputStream(data));
  list.add(rec.getIdentifier());
  Iterator<DataIdentifier> itr = ds.getAllIdentifiers();
  while (itr.hasNext()) {
    assertTrue("record found on list", list.remove(itr.next()));
  }
  assertEquals(0, list.size());
  ds.close();
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testAlternateBucketProp() throws Exception {
  assumeTrue(isS3Configured());
  Random randomGen = new Random();
  props = S3DataStoreUtils.getS3Config();
  //Replace bucket in props with container
  bucket = props.getProperty(S3Constants.S3_BUCKET);
  props.remove(S3Constants.S3_BUCKET);
  props.put(S3Constants.S3_CONTAINER, bucket);
  props.put("cacheSize", "0");
  ds = getS3DataStore(s3Class, props, dataStoreDir.getAbsolutePath());
  byte[] data = new byte[4096];
  randomGen.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  assertEquals(data.length, rec.getLength());
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test if record can be accessed via
 * {@link DataStore#getRecordFromReference(String)}
 */
protected void doReferenceTest() throws Exception {
  ds = createDataStore();
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  String reference;
  DataRecord record = ds.addRecord(new ByteArrayInputStream(data));
  reference = record.getReference();
  assertReference(data, reference, ds);
  ds.close();
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Test {@link DataStore#getRecord(DataIdentifier)} and assert length and
 * inputstream.
 */
protected void doGetRecordTest() throws Exception {
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  rec = ds.getRecord(rec.getIdentifier());
  Assert.assertEquals(data.length, rec.getLength());
  assertRecord(data, rec);
}

代码示例来源:origin: apache/jackrabbit

void doTest(DataStore ds, int offset) throws Exception {
  ArrayList<DataRecord> list = new ArrayList<DataRecord>();
  HashMap<DataRecord, Integer> map = new HashMap<DataRecord, Integer>();
  for (int i = 0; i < 100; i++) {
    int size = 100 + i * 10;
    RandomInputStream in = new RandomInputStream(size + offset, size);
    DataRecord rec = ds.addRecord(in);
    list.add(rec);
    map.put(rec, new Integer(size));
  }
  Random random = new Random(1);
  for (int i = 0; i < list.size(); i++) {
    int pos = random.nextInt(list.size());
    DataRecord rec = list.get(pos);
    int size = map.get(rec);
    rec = ds.getRecord(rec.getIdentifier());
    assertEquals(size, rec.getLength());
    InputStream in = rec.getStream();
    RandomInputStream expected = new RandomInputStream(size + offset, size);
    if (random.nextBoolean()) {
      in = readInputStreamRandomly(in, random);
    }
    assertEquals(expected, in);
    in.close();
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link DataStore#addRecord(InputStream)} and assert length of added
 * record.
 */
protected void doAddRecordTest() throws Exception {
  ds = createDataStore();
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  assertEquals(data.length, rec.getLength());
  assertRecord(data, rec);
  ds.close();
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
 */
protected void doDeleteRecordTest() throws Exception {
  Random random = randomGen;
  byte[] data1 = new byte[dataLength];
  random.nextBytes(data1);
  DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));
  byte[] data2 = new byte[dataLength];
  random.nextBytes(data2);
  DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));
  byte[] data3 = new byte[dataLength];
  random.nextBytes(data3);
  DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));
  ((MultiDataStoreAware)ds).deleteRecord(rec1.getIdentifier());
  assertNull("rec1 should be null",
    ds.getRecordIfStored(rec1.getIdentifier()));
  assertEquals(new ByteArrayInputStream(data2),
    ds.getRecord(rec2.getIdentifier()).getStream());
  assertEquals(new ByteArrayInputStream(data3),
    ds.getRecord(rec3.getIdentifier()).getStream());
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void assertReferenceKey() throws Exception {
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  Assert.assertEquals(data.length, rec.getLength());
  assertRecord(data, rec);
  DataRecord refRec = ds.getRecordFromReference(rec.getReference());
  assertRecord(data, refRec);
  // Check bytes retrieved from reference.key file
  File refFile = new File(fsBackendPath, "reference.key");
  assertTrue(refFile.exists());
  byte[] keyRet = FileUtils.readFileToByteArray(refFile);
  assertTrue(keyRet.length != 0);
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
 */
protected void doDeleteRecordTest() throws Exception {
  ds = createDataStore();
  Random random = randomGen;
  byte[] data1 = new byte[dataLength];
  random.nextBytes(data1);
  DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));
  byte[] data2 = new byte[dataLength];
  random.nextBytes(data2);
  DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));
  byte[] data3 = new byte[dataLength];
  random.nextBytes(data3);
  DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));
  ((MultiDataStoreAware)ds).deleteRecord(rec2.getIdentifier());
  assertNull("rec2 should be null",
    ds.getRecordIfStored(rec2.getIdentifier()));
  assertEquals(new ByteArrayInputStream(data1),
    ds.getRecord(rec1.getIdentifier()).getStream());
  assertEquals(new ByteArrayInputStream(data3),
    ds.getRecord(rec3.getIdentifier()).getStream());
  ds.close();
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link DataStore#getRecord(DataIdentifier)} and assert length and
 * inputstream.
 */
protected void doGetRecordTest() throws Exception {
  ds = createDataStore();
  byte[] data = new byte[dataLength];
  randomGen.nextBytes(data);
  DataRecord rec = ds.addRecord(new ByteArrayInputStream(data));
  rec = ds.getRecord(rec.getIdentifier());
  assertEquals(data.length, rec.getLength());
  assertRecord(data, rec);
  ds.close();
}

相关文章