本文整理汇总了Java中org.javaswift.joss.model.StoredObject.getEtag方法的典型用法代码示例。如果您正苦于以下问题:Java StoredObject.getEtag方法的具体用法?Java StoredObject.getEtag怎么用?Java StoredObject.getEtag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.javaswift.joss.model.StoredObject
的用法示例。
在下文中一共展示了StoredObject.getEtag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RemoteItem
import org.javaswift.joss.model.StoredObject; //导入方法依赖的package包/类
public RemoteItem (StoredObject storedObject) throws IOException
{
super () ;
if (storedObject == null)
throw new IllegalArgumentException ("storedObject cannot be null") ;
this.storedObject = storedObject ;
this.exists = storedObject.exists() ;
this.size = (exists) ? (storedObject.getContentLength()) : (-2) ;
if (exists)
{
// For segmented object, the etag may be bounded by "".
String etag = storedObject.getEtag() ;
if (etag.startsWith("\""))
etag = etag.replace("\"", "") ;
this.md5 = etag ;
}
else
this.md5 = "" ;
}
示例2: uploadAndOverwrite
import org.javaswift.joss.model.StoredObject; //导入方法依赖的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) ;
}
示例3: shouldNotUploadStoredObjectCollection
import org.javaswift.joss.model.StoredObject; //导入方法依赖的package包/类
@Test
public void shouldNotUploadStoredObjectCollection() throws IOException
{
Container container = account.getContainer("x").create();
StoredObject object1 = container.getObject("object1");
object1.uploadObject(TestUtils.getTestFile(tmpFolder, "src1", 8192));
assertTrue (object1.exists()) ;
StoredObject object2 = container.getObject("dir" + SwiftUtils.separator + "object2");
object2.uploadObject(TestUtils.getTestFile(tmpFolder, "src1", 8192));
assertTrue (object2.exists()) ;
String etag1 = object1.getEtag() ;
String etag2 = object2.getEtag() ;
File file1 = TestUtils.getTestFile(tmpFolder, "file1", 4096) ;
File file2 = TestUtils.getTestFile(tmpFolder, "file2", 4096) ;
String hash1 = FileUtils.getMD5(file1) ;
String hash2 = FileUtils.getMD5(file2) ;
assertFalse (hash1.equals(etag1)) ;
assertFalse (hash2.equals(etag2)) ;
List<Pair<? extends StoredObject, ? extends File> > pairObjectFile = new ArrayList<> () ;
pairObjectFile.add(Pair.newPair(object1, file1)) ;
pairObjectFile.add(Pair.newPair(object2, file2)) ;
boolean overwrite = false ;
ops.uploadFiles(container, pairObjectFile, overwrite, stopRequester, callback);
assertTrue (etag1.equals(object1.getEtag())) ;
assertTrue (etag2.equals(object2.getEtag())) ;
}
示例4: uploadSegmentedObjects
import org.javaswift.joss.model.StoredObject; //导入方法依赖的package包/类
private void uploadSegmentedObjects(AbstractContainer abstractContainer, AbstractStoredObject obj, File file, UploadInstructions uploadInstructions, long size, ProgressInformation progInfo, SwiftCallback callback)
{
if (size < uploadInstructions.getSegmentationSize())
throw new AssertionError (String.format("The file size (%d) must be greater than the segmentation size (%d)", size, uploadInstructions.getSegmentationSize())) ;
StringBuilder pathBuilder = new StringBuilder () ;
pathBuilder.append(abstractContainer.getName()) ;
pathBuilder.append(SwiftUtils.separator) ;
pathBuilder.append(obj.getName()) ;
String path = pathBuilder.toString() ;
Set<StoredObject> segmentsSet = new TreeSet<> () ;
try
{
logger.info("Setting up a segmentation plan for " + path);
Map<Long, String> md5PlanMap = null ;
String currMsg = progInfo.getCurrentMessage() ;
if (checkExistingSegments /*&& !obj.exists()*/)
md5PlanMap = getMd5PlanMap (uploadInstructions, obj, file, progInfo) ;
SegmentationPlan plan = uploadInstructions.getSegmentationPlan();
long numSegments = getNumberOfSegments (size, uploadInstructions) ;
InputStream segmentStream = FileUtils.getInputStreamWithProgressFilter(progInfo, uploadInstructions.getSegmentationSize(), plan.getNextSegment()) ;
while (segmentStream != null)
{
Long planSeg = plan.getSegmentNumber() ;
logger.info("Uploading segment " + planSeg);
progInfo.setCurrentMessage(String.format("%s (segment %d / %d)", currMsg, planSeg, numSegments));
StoredObject segment = getObjectSegment(abstractContainer, obj, planSeg);
segmentsSet.add(segment) ;
// check if this segment can be ignored
boolean ignore = false ;
if (md5PlanMap != null && !md5PlanMap.isEmpty())
{
if (segment.exists() && md5PlanMap.containsKey(planSeg))
{
String etag = segment.getEtag() ;
String md5 = md5PlanMap.get(planSeg) ;
if (etag != null && etag.equals(md5))
ignore = true ;
}
if (ignore)
logger.info("{} already exists and has not changed (it won't be uploaded again)", String.format("Segment %d / %d", planSeg, numSegments)) ;
}
if (!ignore)
segment.uploadObject(segmentStream);
segmentStream.close();
segmentStream = FileUtils.getInputStreamWithProgressFilter(progInfo, (planSeg + 1 != numSegments)?(uploadInstructions.getSegmentationSize()):(size % uploadInstructions.getSegmentationSize()), plan.getNextSegment());
}
// we must remove extra segments that might remain from a previous large object with the same name
cleanUpExtraSegments (obj, segmentsSet) ;
}
catch (IOException err)
{
logger.error("Failed to set up a segmentation plan for " + path + ": " + err.getMessage());
callback.onError(new CommandException("Unable to upload segments", err));
}
}
示例5: shouldBeIgnored
import org.javaswift.joss.model.StoredObject; //导入方法依赖的package包/类
private boolean shouldBeIgnored (StoredObject obj, Path path, boolean overwrite) throws IOException
{
if (obj == null)
return true ;
if (path == null)
return true ;
if (obj.exists())
{
if (Files.isDirectory(path))
return true ; // the folder already exists
// the computation of the md5 value is quite resource demanding (when done for
// a lots of large files)
if (!overwrite)
{
logger.info("The file '{}' already exists in the cloud. It has been ignored.", path.toString());
return true ;
}
String etag = obj.getEtag() ;
String md5 = FileUtils.getMD5(path.toFile()) ;
// the file is already uploaded, unless this is a collision... But we would then be quite unlucky
// TODO: check other information in order to increase the confidence that the file is the same.
// ...
if (etag != null && etag.equals(md5))
{
logger.info("The file '{}' already exists in the cloud.", path.toString());
return true ;
}
else
{
if (largeObjectManager != null && largeObjectManager.isSegmented(obj))
{
md5 = FileUtils.getSumOfSegmentsMd5(path.toFile(), getActualSegmentSize (obj)) ;
if (etag.startsWith("\"")) ;
etag = etag.replace("\"", "") ;
if (etag != null && etag.equals(md5))
{
logger.info("The large file '{}' already exists in the cloud.", path.toString());
return true ;
}
}
logger.info("A different version of the file '{}' already exists in the cloud. It {}.", path.toString(), (overwrite)?("will be overwritten"):("has been ignored"));
if (!overwrite)
return true ;
}
}
return false ;
}