use of com.zimbra.cs.store.IncomingBlob in project zm-mailbox by Zimbra.
the class StoreManagerNegativeTest method incorrectRemoteSize.
@Test
public void incorrectRemoteSize() throws Exception {
Random rand = new Random();
byte[] bytes = new byte[10000];
rand.nextBytes(bytes);
StoreManager sm = StoreManager.getInstance();
IncomingBlob incoming = sm.newIncomingBlob("foo", null);
OutputStream out = incoming.getAppendingOutputStream();
out.write(bytes);
try {
incoming.getCurrentSize();
Assert.fail("Expected exception since remote size is incorrect");
} catch (IOException ioe) {
//expected
}
}
use of com.zimbra.cs.store.IncomingBlob in project zm-mailbox by Zimbra.
the class StoreManagerNegativeTest method nullLocator.
@Test
public void nullLocator() throws Exception {
Random rand = new Random();
byte[] bytes = new byte[10000];
rand.nextBytes(bytes);
StoreManager sm = StoreManager.getInstance();
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
IncomingBlob incoming = sm.newIncomingBlob("foo", null);
OutputStream out = incoming.getAppendingOutputStream();
out.write(bytes);
Blob blob = incoming.getBlob();
Assert.assertEquals("blob size = incoming written", bytes.length, blob.getRawSize());
Assert.assertTrue("blob content = mime content", TestUtil.bytesEqual(bytes, blob.getInputStream()));
StagedBlob staged = sm.stage(blob, mbox);
Assert.assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
Assert.assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
try {
mblob.getLocalBlob().getInputStream();
Assert.fail("Expected IOException since locator is not handled correctly");
} catch (IOException io) {
//expected
} finally {
sm.delete(mblob);
}
}
use of com.zimbra.cs.store.IncomingBlob in project zm-mailbox by Zimbra.
the class PatchStore method acceptPatch.
/**
* Accepts patch. Turns an IncomingPatch into a StoredPatch.
*
* @param ip The IncomingPatch instance to accept.
* @param fileId The id of the file the patch creates.
* @param version the version The version number of the file the patch creates.
* @param manifest The patch manifest.
*
* @return StoredPatch instance.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws ServiceException the service exception
*/
public StoredPatch acceptPatch(IncomingPatch ip, int fileId, int version) throws IOException, ServiceException {
if (version > 1) {
deletePatch(ip.getAccountId(), fileId);
}
IncomingBlob manifestBlob = blobStore.createIncoming(null);
try {
ip.getManifest().writeTo(manifestBlob.getAppendingOutputStream());
} catch (IOException e) {
blobStore.deleteIncoming(manifestBlob);
throw e;
}
// ok, we got manifest written to a separate incoming blob here, now let's store both
StoredBlob psb = blobStore.store(ip.patchBlob, getStoredPatchId(ip.getAccountId(), fileId, false), version);
StoredBlob msb = null;
try {
msb = blobStore.store(manifestBlob, getStoredPatchId(ip.getAccountId(), fileId, true), version);
} catch (IOException e) {
blobStore.delete(psb, version);
throw e;
}
StoredPatch sp = new StoredPatch(psb, msb, ip.getAccountId());
psb.setContext(sp);
return sp;
}
use of com.zimbra.cs.store.IncomingBlob in project zm-mailbox by Zimbra.
the class StoreManagerBasedTempBlobStore method createIncoming.
// BlobStore API
@Override
public IncomingBlob createIncoming(Object ctx) throws IOException, ServiceException {
synchronized (incomingBlobs) {
String id;
do {
id = UUID.randomUUID().toString();
} while (incomingBlobs.containsKey(id));
IncomingBlob ib = storeManager.newIncomingBlob(id, ctx);
incomingBlobs.put(id, ib);
return ib;
}
}
use of com.zimbra.cs.store.IncomingBlob in project zm-mailbox by Zimbra.
the class StoreManagerBasedTempBlobStore method store.
// BlobStore API
@Override
public StoredBlob store(IncomingBlob ib, String id, int version) throws IOException, ServiceException {
IncomingBlob myIb = ib;
synchronized (incomingBlobs) {
IncomingBlob existingBlob = incomingBlobs.remove(myIb.getId());
if (existingBlob == null) {
// because the underlying file is gone
throw ServiceException.INVALID_REQUEST("Cannot accept incoming blob " + myIb.getId(), null);
}
assert existingBlob == myIb : "Wrong blob removed: " + myIb.getId();
}
Blob blob = myIb.getBlob();
StoredBlob sb = new StoredBlob(id, blob, myIb.getContext(), blob.getRawSize());
if (storedCached) {
synchronized (storedBlobs) {
TreeMap<Integer, StoredBlob> versionMap = storedBlobs.get(id);
if (versionMap == null) {
versionMap = new TreeMap<Integer, StoredBlob>();
storedBlobs.put(id, versionMap);
}
Integer versionInt = Integer.valueOf(version);
assert !versionMap.containsKey(versionInt) : "Version " + version + " already exists";
versionMap.put(versionInt, sb);
}
}
return sb;
}
Aggregations