本文整理汇总了Java中org.javaswift.joss.model.Container类的典型用法代码示例。如果您正苦于以下问题:Java Container类的具体用法?Java Container怎么用?Java Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Container类属于org.javaswift.joss.model包,在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: flush
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Override
public void flush(Map<TopicPartition, OffsetAndMetadata> currentOffsets) {
try {
Iterator<BulkedData> items = bulker.convert();
while (items.hasNext()) {
final BulkedData item = items.next();
final Container container = this.account.getContainer(item.getContainer());
if (!container.exists()) {
container.create();
}
final StoredObject object = container.getObject(item.getObject());
object.uploadObject(item.getStream());
}
} catch (Exception exception) {
log.error("Failed to add record", exception);
throw new ConnectException("Failed to flush", exception);
}
}
示例2: rename
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Override
public boolean rename(String hostName, String srcPath, String dstPath) throws IOException {
LOG.debug("Rename from {} to {}. hostname is {}", srcPath, dstPath, hostName);
String objNameSrc = srcPath.toString();
if (srcPath.toString().startsWith(hostName)) {
objNameSrc = getObjName(hostName, srcPath);
}
String objNameDst = dstPath.toString();
if (objNameDst.toString().startsWith(hostName)) {
objNameDst = getObjName(hostName, dstPath);
}
if (stocatorPath.isTemporaryPathContain(objNameSrc)) {
LOG.debug("Rename on the temp object {}. Return true", objNameSrc);
return true;
}
LOG.debug("Rename modified from {} to {}", objNameSrc, objNameDst);
Container cont = mJossAccount.getAccount().getContainer(container);
StoredObject so = cont.getObject(objNameSrc);
StoredObject soDst = cont.getObject(objNameDst);
so.copyObject(cont, soDst);
return true;
}
示例3: shouldNotDownloadStoredObject
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Test(expected = AssertionError.class)
public void shouldNotDownloadStoredObject()
{
final String directoryName = "directory" ;
Container container = account.getContainer("x").create();
ops.createDirectory(container, null, directoryName, callback);
StoredObject objectDir = container.getObject(directoryName);
assertTrue (objectDir.exists()) ;
try
{
ops.downloadStoredObject(container, objectDir, tmpFolder.newFile(), null, callback);
}
catch (IOException e)
{
logger.error ("Error occurred in shouldNotDownloadStoredObject", e) ;
assertFalse(true) ;
}
}
示例4: shouldGetAllContainedStoredObjectInContainer
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Test
public void shouldGetAllContainedStoredObjectInContainer () throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException
{
Container container = account.getContainer("x").create();
StoredObject object1 = container.getObject("obj1");
object1.uploadObject(new byte[]{'a', 'b', 'c'});
StoredObject objectDir1 = container.getObject("dir1");
objectDir1.uploadObject(new UploadInstructions (new byte[] {}).setContentType(SwiftUtils.directoryContentType)) ;
StoredObject object2 = container.getObject(objectDir1.getName() + SwiftUtils.separator + "obj2");
object2.uploadObject(new byte[]{'a', 'b', 'c'});
StoredObject objectDir2 = container.getObject(objectDir1.getName() + SwiftUtils.separator + "subDir");
objectDir2.uploadObject(new UploadInstructions (new byte[] {}).setContentType(SwiftUtils.directoryContentType)) ;
// call a private method via reflection
Class<?> c = SwiftOperationsImpl.class;
Method method = c.getDeclaredMethod ("getAllContainedStoredObject", Container.class, Directory.class);
method.setAccessible(true);
@SuppressWarnings("unchecked")
Collection<StoredObject> ret = (Collection<StoredObject>) method.invoke(ops, container, null);
assertTrue (ret.size() == 4) ;
}
示例5: shouldUploadStoredObject
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Test
public void shouldUploadStoredObject() throws IOException
{
Container container = account.getContainer("x").create();
final String dir = "dir" ;
final String name = "file.dat" ;
StoredObject object = container.getObject(dir);
object.uploadObject(new UploadInstructions (new byte[] {}).setContentType(SwiftUtils.directoryContentType)) ;
File file = TestUtils.getTestFile(tmpFolder, name, 4096) ;
ops.uploadFiles(container, object, new File [] {file}, true, stopRequester, callback);
//Mockito.verify(callback, Mockito.atLeastOnce()).onNewStoredObjects();
Mockito.verify(callback, Mockito.atLeastOnce()).onAppendStoredObjects(Mockito.any(Container.class), Mockito.eq(0),
Mockito.anyListOf(StoredObject.class));
StoredObject upObj = container.getObject(dir + SwiftUtils.separator + name) ;
assertTrue (upObj.exists());
assertTrue (upObj.getEtag().equals(FileUtils.getMD5(file))) ;
}
示例6: uploadObjectAsSegments
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Override
public void uploadObjectAsSegments(StoredObject obj, File file, UploadInstructions uploadInstructions, long size, ProgressInformation progInfo, SwiftCallback callback)
{
Container segmentsContainer = getSegmentsContainer (obj, true) ;
AbstractContainer abstractContainer = (AbstractContainer)segmentsContainer ;
uploadSegmentedObjects(abstractContainer, (AbstractStoredObject)obj, file, uploadInstructions, size, progInfo, callback);
StringBuilder sb = new StringBuilder () ;
sb.append(segmentsContainer.getName()) ;
sb.append(obj.getPath().replaceFirst(((AbstractStoredObject)obj).getContainer().getPath(), "")) ;
UploadInstructions manifest = new UploadInstructions(new byte[] {})
.setObjectManifest(new ObjectManifest(sb.toString())) // Manifest does not accept preceding slash
.setContentType(uploadInstructions.getContentType()
);
obj.uploadObject(manifest);
}
示例7: shouldReturnObjectFile
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Test
public void shouldReturnObjectFile () throws IOException
{
Container container = account.getContainer("x").create() ;
final String root = "root" ;
File rootDirectory = TestUtils.getTestDirectoryWithFiles (tmpFolder, root, "file", 2) ;
Path file = Paths.get(new File (rootDirectory.getPath() + File.separator + "file_1").getPath()) ;
assertTrue (Files.exists(file)) ;
DifferencesFinder.LocalItem li = new DifferencesFinder.LocalItem(file, Paths.get(rootDirectory.getPath()), Long.MAX_VALUE) ;
StoredObject obj = container.getObject(li.getRemoteFullName()) ;
obj.uploadObject(new byte[]{'a', 'b', 'c'}) ;
assertTrue (obj.exists()) ;
DifferencesFinder.RemoteItem ri = new DifferencesFinder.RemoteItem(obj) ;
assertTrue (Paths.get(DifferencesFinder.getFile(ri, rootDirectory).getPath()).equals(file)) ;
}
示例8: getActualSegmentSize
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Override
public long getActualSegmentSize (StoredObject obj)
{
final long notFound = -1 ;
Container segCont = getSegmentsContainer (obj, false) ;
if (segCont == null || !segCont.exists())
return notFound ;
StoredObject segObj = getObjectSegment ((AbstractContainer)segCont, (AbstractStoredObject)obj, Long.valueOf(1)) ;
if (segObj == null || !segObj.exists())
{
// the object may have been segmented using another convention,
// we check using the manifest
List<StoredObject> sgl = getSegmentsList(obj, 0, 1) ;
if (!sgl.isEmpty())
segObj = sgl.get(0) ;
}
if (segObj == null || !segObj.exists())
return notFound ;
return segObj.getContentLength() ;
}
示例9: shouldStopUploadingDirectory
import org.javaswift.joss.model.Container; //导入依赖的package包/类
@Test
public void shouldStopUploadingDirectory ()
{
final String directoryName = "directory" ;
Container container = account.getContainer("x").create();
try
{
SwiftOperationStopRequesterImpl stopReq = new SwiftOperationStopRequesterImpl () ;
stopReq.stop();
File folder = TestUtils.getTestDirectoryWithFiles (tmpFolder, directoryName, "file", 10) ;
ops.uploadDirectory(container, null, folder, true, stopReq, callback);
Mockito.verify(callback, Mockito.times(1)).onStopped();
}
catch (IOException e)
{
logger.error ("Error occurred in shouldStopUploadingDirectory", e) ;
assertFalse(true) ;
}
}
示例10: createContainer
import org.javaswift.joss.model.Container; //导入依赖的package包/类
/**
* {@inheritDoc}.
*/
@Override
public synchronized void createContainer(ContainerSpecification spec, SwiftCallback callback) {
CheckAccount () ;
if (spec != null) {
if (spec.getName().endsWith(SwiftUtils.segmentsContainerPostfix))
throw new AssertionError ("A container name cannot end with \"" + SwiftUtils.segmentsContainerPostfix + "\"") ;
Container c = account.getContainer(spec.getName());
if (!c.exists()) {
c.create();
if (spec.isPrivateContainer()) {
c.makePrivate();
} else {
c.makePublic();
}
}
callback.onUpdateContainers(eagerFetchContainers(account));
callback.onNumberOfCalls(account.getNumberOfCalls());
}
}
示例11: uploadAndOverwrite
import org.javaswift.joss.model.Container; //导入依赖的package包/类
private void uploadAndOverwrite (boolean overwrite) throws IOException
{
final String objName = "testObject.dat" ;
Container container = account.getContainer("x").create();
StoredObject object = container.getObject(objName);
object.uploadObject(TestUtils.getTestFile(tmpFolder, objName, 4096));
assertTrue (object.exists()) ;
String md5 = object.getEtag() ;
// upload a new file with the same name, the overwrite flag is set to overwrite
ops.uploadFiles(container, null, new File [] {TestUtils.getTestFile(tmpFolder, objName, 4096)}, overwrite, stopRequester, callback);
StoredObject newObject = container.getObject(objName);
assertTrue (newObject.exists()) ;
// we assume no collision ;-)
assertTrue (md5.equals(newObject.getEtag()) == !overwrite) ;
}
示例12: addedObjectToContainer
import org.javaswift.joss.model.Container; //导入依赖的package包/类
private void addedObjectToContainer(Container container, List<StoredObject> newObjects, SwiftCallback callback) {
if (container == null)
throw new AssertionError ("container cannot be null") ;
container.reload();
if (newObjects == null || newObjects.isEmpty())
return ;
int page = 0;
while (page * MAX_PAGE_SIZE < newObjects.size())
{
callback.onAppendStoredObjects(container, page, newObjects.subList(page * MAX_PAGE_SIZE, Math.min(newObjects.size(), (page + 1) * MAX_PAGE_SIZE))) ;
++page ;
}
}
示例13: getAllContainedStoredObject
import org.javaswift.joss.model.Container; //导入依赖的package包/类
private Collection<StoredObject> getAllContainedStoredObject (Container container, Directory parent)
{
Set<StoredObject> results = new TreeSet<StoredObject>();
Queue<DirectoryOrObject> queue = new ArrayDeque<DirectoryOrObject> () ;
queue.addAll((parent == null) ? (container.listDirectory()) : (container.listDirectory(parent))) ;
while (!queue.isEmpty())
{
DirectoryOrObject currDirOrObj = queue.poll() ;
if (currDirOrObj != null)
{
if (currDirOrObj.isObject())
results.add(currDirOrObj.getAsObject()) ;
if (currDirOrObj.isDirectory())
queue.addAll(container.listDirectory(currDirOrObj.getAsDirectory())) ;
}
}
return results ;
}
示例14: findDifferences
import org.javaswift.joss.model.Container; //导入依赖的package包/类
/**
* {@inheritDoc}.
* @throws IOException
*/
@Override
public synchronized void findDifferences (Container container, StoredObject remote, File local, ResultCallback<Collection<Pair<? extends ComparisonItem, ? extends ComparisonItem> > > resultCallback, StopRequester stopRequester, SwiftCallback callback) throws IOException
{
CheckAccount () ;
if (!remote.getBareName().equals(local.getName()))
throw new IllegalArgumentException ("The local and the remote items must have the same name") ;
if (SwiftUtils.isDirectory(remote) && Files.isDirectory(Paths.get(local.getPath()))) {
// here we compare two folders
findDirectoriesDifferences (container, remote, local, resultCallback, stopRequester, callback) ;
}
else if (SwiftUtils.isDirectory(remote)) {
throw new AssertionError ("A remote directory can only be compared with a local directory") ;
}
else{
// here we only compare two "files"
findFilesDifferences (container, remote, local, resultCallback, stopRequester, callback) ;
}
}
示例15: getObjectRelativelyInDirectory
import org.javaswift.joss.model.Container; //导入依赖的package包/类
private StoredObject getObjectRelativelyInDirectory (Container container, String parentDir, Path source, Path path)
{
final String separator = SwiftUtils.separator ;
StringBuilder objectPathBuilder = new StringBuilder () ;
if (parentDir != null)
objectPathBuilder.append (parentDir) ;
objectPathBuilder.append (source.getFileName().toString()) ;
objectPathBuilder.append(separator) ;
objectPathBuilder.append(source.relativize(path).toString()) ;
String objectPath = objectPathBuilder.toString() ;
if (!separator.equals(File.separator))
objectPath = objectPath.replace(File.separator, separator) ;
// relevant when creating folder
if (objectPath.length() > 1 && objectPath.endsWith(separator))
objectPath = objectPath.substring(0, objectPath.length() - 1) ;
return container.getObject(objectPath.toString());
}