use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.
the class AbstractExternalStoreManagerTest method testUncachedFile.
@Test
public void testUncachedFile() throws Exception {
ParsedMessage pm = ThreaderTest.getRootMessage();
byte[] mimeBytes = TestUtil.readInputStream(pm.getRawInputStream());
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
StoreManager sm = StoreManager.getInstance();
Blob blob = sm.storeIncoming(pm.getRawInputStream());
StagedBlob staged = sm.stage(blob, mbox);
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
Blob localBlob = mblob.getLocalBlob();
InputStream stream = sm.getContent(localBlob);
Assert.assertTrue("input stream external", stream instanceof BlobInputStream);
if (sm instanceof ExternalStoreManager) {
((ExternalStoreManager) sm).clearCache();
}
blob.getFile().delete();
Assert.assertFalse(blob.getFile().exists());
//now get it again. this would bomb if it only looked in cache
stream = sm.getContent(mblob.getLocalBlob());
Assert.assertTrue("input stream external", stream instanceof ExternalBlobInputStream);
ExternalBlobInputStream extStream = (ExternalBlobInputStream) stream;
File file = extStream.getRootFile();
Assert.assertTrue(file.exists());
Assert.assertTrue("stream content = mime content", TestUtil.bytesEqual(mimeBytes, stream));
}
use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.
the class ExternalBlobInputStream method getRootFile.
@Override
protected File getRootFile() throws IOException {
File file = super.getRootFile();
if (file != null && file.exists()) {
return file;
} else {
ZimbraLog.store.debug("blob file no longer on disk, fetching from remote store");
ExternalStoreManager sm = (ExternalStoreManager) StoreManager.getInstance();
Blob blob = sm.getLocalBlob(mbox, locator, false);
return blob.getFile();
}
}
use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.
the class ExternalMailboxBlob method getLocalBlob.
@Override
public Blob getLocalBlob() throws IOException {
ExternalStoreManager sm = (ExternalStoreManager) StoreManager.getInstance();
Blob blob = sm.getLocalBlob(getMailbox(), getLocator());
setSize(blob.getRawSize());
if (digest != null) {
setDigest(blob.getDigest());
}
return blob;
}
use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.
the class ExternalStoreManager method stage.
@Override
public StagedBlob stage(InputStream in, long actualSize, Mailbox mbox) throws ServiceException, IOException {
if (actualSize < 0) {
Blob blob = storeIncoming(in);
try {
return stage(blob, mbox);
} finally {
quietDelete(blob);
}
}
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
throw ServiceException.FAILURE("SHA-256 digest not found", e);
}
ByteUtil.PositionInputStream pin = new ByteUtil.PositionInputStream(new DigestInputStream(in, digest));
try {
String locator = writeStreamToStore(pin, actualSize, mbox);
if (locator != null) {
ZimbraLog.store.debug("wrote to locator %s", locator);
} else {
ZimbraLog.store.warn("blob staging returned null locator");
}
return new ExternalStagedBlob(mbox, ByteUtil.encodeFSSafeBase64(digest.digest()), pin.getPosition(), locator);
} catch (IOException e) {
throw ServiceException.FAILURE("unable to stage blob", e);
}
}
use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.
the class ExternalBlobConsistencyChecker method checkExternalBlob.
private void checkExternalBlob(Mailbox mbox, boolean checkSize, BlobInfo blobInfo, ExternalStoreManager sm) throws ServiceException {
MailboxBlob mblob = sm.getMailboxBlob(mbox, blobInfo.itemId, blobInfo.version, blobInfo.path, false);
if (mblob == null) {
results.missingBlobs.put(blobInfo.itemId, blobInfo);
} else {
try {
unexpectedBlobPaths.remove(mblob.getLocator());
Blob blob = sm.getLocalBlob(mbox, mblob.getLocator(), false);
if (blob == null) {
results.missingBlobs.put(blobInfo.itemId, blobInfo);
} else {
//blob exists for the locator
blobInfo.fileModContent = blobInfo.modContent;
if (reportUsedBlobs) {
results.usedBlobs.put(blobInfo.itemId, blobInfo);
}
if (checkSize) {
blobInfo.fileSize = blob.getFile().length();
blobInfo.fileDataSize = getDataSize(blob.getFile(), blobInfo.dbSize);
if (blobInfo.dbSize != blobInfo.fileDataSize) {
results.incorrectSize.put(blobInfo.itemId, blobInfo);
}
}
}
} catch (Exception e) {
blobInfo.fetchException = e instanceof IOException ? (IOException) e : new IOException("Exception fetching blob", e);
results.missingBlobs.put(blobInfo.itemId, blobInfo);
}
}
}
Aggregations