List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:com.eucalyptus.walrus.WalrusFSManager.java
@Override public CopyObjectResponseType copyObject(CopyObjectType request) throws WalrusException { CopyObjectResponseType reply = (CopyObjectResponseType) request.getReply(); Context ctx = Contexts.lookup(); Account account = ctx.getAccount();//from w w w . j ava 2 s . c o m String sourceBucket = request.getSourceBucket(); String sourceKey = request.getSourceObject(); String sourceVersionId = request.getSourceVersionId(); String destinationBucket = request.getDestinationBucket(); String destinationKey = request.getDestinationObject(); String metadataDirective = request.getMetadataDirective(); AccessControlList accessControlList = request.getAccessControlList(); String copyIfMatch = request.getCopySourceIfMatch(); String copyIfNoneMatch = request.getCopySourceIfNoneMatch(); Date copyIfUnmodifiedSince = request.getCopySourceIfUnmodifiedSince(); Date copyIfModifiedSince = request.getCopySourceIfModifiedSince(); if (metadataDirective == null) { metadataDirective = "COPY"; } EntityWrapper<BucketInfo> db = EntityWrapper.get(BucketInfo.class); BucketInfo bucketInfo = new BucketInfo(sourceBucket); List<BucketInfo> bucketList = db.queryEscape(bucketInfo); if (bucketList.size() > 0) { EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class); ObjectInfo searchObjectInfo = new ObjectInfo(sourceBucket, sourceKey); searchObjectInfo.setVersionId(sourceVersionId); if (sourceVersionId == null) { searchObjectInfo.setLast(true); } List<ObjectInfo> objectInfos = dbObject.queryEscape(searchObjectInfo); if (objectInfos.size() > 0) { ObjectInfo sourceObjectInfo = objectInfos.get(0); if (copyIfMatch != null) { if (!copyIfMatch.equals(sourceObjectInfo.getEtag())) { db.rollback(); throw new PreconditionFailedException(sourceKey + " CopySourceIfMatch: " + copyIfMatch); } } if (copyIfNoneMatch != null) { if (copyIfNoneMatch.equals(sourceObjectInfo.getEtag())) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfNoneMatch: " + copyIfNoneMatch); } } if (copyIfUnmodifiedSince != null) { long unmodifiedTime = copyIfUnmodifiedSince.getTime(); long objectTime = sourceObjectInfo.getLastModified().getTime(); if (unmodifiedTime < objectTime) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfUnmodifiedSince: " + copyIfUnmodifiedSince.toString()); } } if (copyIfModifiedSince != null) { long modifiedTime = copyIfModifiedSince.getTime(); long objectTime = sourceObjectInfo.getLastModified().getTime(); if (modifiedTime > objectTime) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfModifiedSince: " + copyIfModifiedSince.toString()); } } BucketInfo destinationBucketInfo = new BucketInfo(destinationBucket); List<BucketInfo> destinationBuckets = db.queryEscape(destinationBucketInfo); if (destinationBuckets.size() > 0) { BucketInfo foundDestinationBucketInfo = destinationBuckets.get(0); if (ctx.hasAdministrativePrivileges() || (foundDestinationBucketInfo.canWrite(account.getAccountNumber()) && (foundDestinationBucketInfo.isGlobalWrite() || Lookups.checkPrivilege(PolicySpec.S3_PUTOBJECT, PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_BUCKET, destinationBucket, null)))) { // all ok Long destinationObjectOldSize = 0L; String destinationVersionId = sourceVersionId; ObjectInfo destinationObjectInfo = null; String destinationObjectName; ObjectInfo destSearchObjectInfo = new ObjectInfo(destinationBucket, destinationKey); if (foundDestinationBucketInfo.isVersioningEnabled()) { destinationVersionId = UUID.randomUUID().toString().replaceAll("-", ""); } else { destinationVersionId = WalrusProperties.NULL_VERSION_ID; } destSearchObjectInfo.setVersionId(destinationVersionId); List<ObjectInfo> destinationObjectInfos = dbObject.queryEscape(destSearchObjectInfo); if (destinationObjectInfos.size() > 0) { destinationObjectInfo = destinationObjectInfos.get(0); // Check privilege only if its not a delete marker, HACK!! if (!destinationObjectInfo.getDeleted() && !destinationObjectInfo.canWrite(account.getAccountNumber())) { db.rollback(); throw new AccessDeniedException("Key", destinationKey); } } boolean addNew = false; if (destinationObjectInfo == null) { // not found. create a new one addNew = true; destinationObjectInfo = new ObjectInfo(); List<GrantInfo> grantInfos = new ArrayList<GrantInfo>(); destinationObjectInfo.setBucketName(destinationBucket); destinationObjectInfo.setObjectKey(destinationKey); destinationObjectInfo.addGrants(account.getAccountNumber(), foundDestinationBucketInfo.getOwnerId(), grantInfos, accessControlList); destinationObjectInfo.setGrants(grantInfos); destinationObjectInfo.setObjectName(UUID.randomUUID().toString()); } else { // If its a delete marker, make the same checks as when the object was not found, HACK!! List<GrantInfo> grantInfos = new ArrayList<GrantInfo>(); destinationObjectInfo.addGrants(account.getAccountNumber(), foundDestinationBucketInfo.getOwnerId(), grantInfos, accessControlList); destinationObjectInfo.setGrants(grantInfos); destinationObjectOldSize = destinationObjectInfo.getSize() == null ? 0L : destinationObjectInfo.getSize(); } destinationObjectInfo.setSize(sourceObjectInfo.getSize()); destinationObjectInfo.setStorageClass(sourceObjectInfo.getStorageClass()); destinationObjectInfo.setOwnerId(sourceObjectInfo.getOwnerId()); destinationObjectInfo.setContentType(sourceObjectInfo.getContentType()); destinationObjectInfo.setContentDisposition(sourceObjectInfo.getContentDisposition()); String etag = sourceObjectInfo.getEtag(); destinationObjectInfo.setEtag(etag); //Date lastModified = sourceObjectInfo.getLastModified(); // S3 updates the timestamp on copies Date lastModified = new Date(); destinationObjectInfo.setLastModified(lastModified); destinationObjectInfo.setVersionId(destinationVersionId); destinationObjectInfo.setLast(true); destinationObjectInfo.setDeleted(false); if (!metadataDirective.equals("REPLACE")) { destinationObjectInfo.setMetaData(sourceObjectInfo.cloneMetaData()); } else { List<MetaDataEntry> metaData = request.getMetaData(); if (metaData != null) destinationObjectInfo.replaceMetaData(metaData); } String sourceObjectName = sourceObjectInfo.getObjectName(); destinationObjectName = destinationObjectInfo.getObjectName(); try { storageManager.copyObject(sourceBucket, sourceObjectName, destinationBucket, destinationObjectName); } catch (Exception ex) { LOG.error(ex); db.rollback(); throw new InternalErrorException( "Could not rename " + sourceObjectName + " to " + destinationObjectName); } if (addNew) dbObject.add(destinationObjectInfo); reply.setEtag(etag); // Last modified date in copy response is in ISO8601 format as per S3 spec // reply.setLastModified(DateFormatter.dateToListingFormattedString(lastModified)); reply.setLastModified(copyObjectFormat.format(lastModified)); if (foundDestinationBucketInfo.isVersioningEnabled()) { reply.setCopySourceVersionId(sourceVersionId); reply.setVersionId(destinationVersionId); } db.commit(); return reply; } else { db.rollback(); throw new AccessDeniedException("Bucket", destinationBucket); } } else { db.rollback(); throw new NoSuchBucketException(destinationBucket); } } else { db.rollback(); throw new NoSuchEntityException(sourceKey); } } else { db.rollback(); throw new NoSuchBucketException(sourceBucket); } }
From source file:com.eucalyptus.objectstorage.WalrusManager.java
public CopyObjectResponseType copyObject(CopyObjectType request) throws EucalyptusCloudException { CopyObjectResponseType reply = (CopyObjectResponseType) request.getReply(); Context ctx = Contexts.lookup(); Account account = ctx.getAccount();//from ww w . j a v a 2 s. c om String sourceBucket = request.getSourceBucket(); String sourceKey = request.getSourceObject(); String sourceVersionId = request.getSourceVersionId(); String destinationBucket = request.getDestinationBucket(); String destinationKey = request.getDestinationObject(); String metadataDirective = request.getMetadataDirective(); AccessControlListType accessControlList = request.getAccessControlList(); String copyIfMatch = request.getCopySourceIfMatch(); String copyIfNoneMatch = request.getCopySourceIfNoneMatch(); Date copyIfUnmodifiedSince = request.getCopySourceIfUnmodifiedSince(); Date copyIfModifiedSince = request.getCopySourceIfModifiedSince(); if (metadataDirective == null) { metadataDirective = "COPY"; } EntityWrapper<BucketInfo> db = EntityWrapper.get(BucketInfo.class); BucketInfo bucketInfo = new BucketInfo(sourceBucket); List<BucketInfo> bucketList = db.queryEscape(bucketInfo); if (bucketList.size() > 0) { EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class); ObjectInfo searchObjectInfo = new ObjectInfo(sourceBucket, sourceKey); searchObjectInfo.setVersionId(sourceVersionId); if (sourceVersionId == null) { searchObjectInfo.setLast(true); } List<ObjectInfo> objectInfos = dbObject.queryEscape(searchObjectInfo); if (objectInfos.size() > 0) { ObjectInfo sourceObjectInfo = objectInfos.get(0); if (ctx.hasAdministrativePrivileges() || (sourceObjectInfo.canRead(account.getAccountNumber()) && (sourceObjectInfo.isGlobalRead() || Lookups.checkPrivilege(PolicySpec.S3_GETOBJECT, PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_OBJECT, PolicySpec.objectFullName(sourceBucket, sourceKey), null)))) { if (copyIfMatch != null) { if (!copyIfMatch.equals(sourceObjectInfo.getEtag())) { db.rollback(); throw new PreconditionFailedException(sourceKey + " CopySourceIfMatch: " + copyIfMatch); } } if (copyIfNoneMatch != null) { if (copyIfNoneMatch.equals(sourceObjectInfo.getEtag())) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfNoneMatch: " + copyIfNoneMatch); } } if (copyIfUnmodifiedSince != null) { long unmodifiedTime = copyIfUnmodifiedSince.getTime(); long objectTime = sourceObjectInfo.getLastModified().getTime(); if (unmodifiedTime < objectTime) { db.rollback(); throw new PreconditionFailedException(sourceKey + " CopySourceIfUnmodifiedSince: " + copyIfUnmodifiedSince.toString()); } } if (copyIfModifiedSince != null) { long modifiedTime = copyIfModifiedSince.getTime(); long objectTime = sourceObjectInfo.getLastModified().getTime(); if (modifiedTime > objectTime) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfModifiedSince: " + copyIfModifiedSince.toString()); } } BucketInfo destinationBucketInfo = new BucketInfo(destinationBucket); List<BucketInfo> destinationBuckets = db.queryEscape(destinationBucketInfo); if (destinationBuckets.size() > 0) { BucketInfo foundDestinationBucketInfo = destinationBuckets.get(0); if (ctx.hasAdministrativePrivileges() || (foundDestinationBucketInfo .canWrite(account.getAccountNumber()) && (foundDestinationBucketInfo.isGlobalWrite() || Lookups.checkPrivilege(PolicySpec.S3_PUTOBJECT, PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_BUCKET, destinationBucket, null)))) { // all ok Long destinationObjectOldSize = 0L; String destinationVersionId = sourceVersionId; ObjectInfo destinationObjectInfo = null; String destinationObjectName; ObjectInfo destSearchObjectInfo = new ObjectInfo(destinationBucket, destinationKey); if (foundDestinationBucketInfo.isVersioningEnabled()) { destinationVersionId = UUID.randomUUID().toString().replaceAll("-", ""); } else { destinationVersionId = WalrusProperties.NULL_VERSION_ID; } destSearchObjectInfo.setVersionId(destinationVersionId); List<ObjectInfo> destinationObjectInfos = dbObject.queryEscape(destSearchObjectInfo); if (destinationObjectInfos.size() > 0) { destinationObjectInfo = destinationObjectInfos.get(0); // Check privilege only if its not a delete marker, HACK!! if (!destinationObjectInfo.getDeleted() && !destinationObjectInfo.canWrite(account.getAccountNumber())) { db.rollback(); throw new AccessDeniedException("Key", destinationKey); } } boolean addNew = false; if (destinationObjectInfo == null) { // not found. create a new one if (ctx.hasAdministrativePrivileges() || (Permissions.isAuthorized(PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_OBJECT, sourceBucket, ctx.getAccount(), PolicySpec.S3_PUTOBJECT, ctx.getUser()) && Permissions.canAllocate(PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_OBJECT, sourceBucket, PolicySpec.S3_PUTOBJECT, ctx.getUser(), sourceObjectInfo.getSize()))) { addNew = true; destinationObjectInfo = new ObjectInfo(); List<GrantInfo> grantInfos = new ArrayList<GrantInfo>(); destinationObjectInfo.setBucketName(destinationBucket); destinationObjectInfo.setObjectKey(destinationKey); destinationObjectInfo.addGrants(account.getAccountNumber(), foundDestinationBucketInfo.getOwnerId(), grantInfos, accessControlList); destinationObjectInfo.setGrants(grantInfos); destinationObjectInfo.setObjectName(UUID.randomUUID().toString()); } } else { // If its a delete marker, make the same checks as when the object was not found, HACK!! if (ctx.hasAdministrativePrivileges() || (destinationObjectInfo.getDeleted() && Permissions.isAuthorized(PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_OBJECT, sourceBucket, ctx.getAccount(), PolicySpec.S3_PUTOBJECT, ctx.getUser()) && Permissions.canAllocate(PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_OBJECT, sourceBucket, PolicySpec.S3_PUTOBJECT, ctx.getUser(), sourceObjectInfo.getSize())) || (destinationObjectInfo.canWriteACP(account.getAccountNumber()) && (destinationObjectInfo.isGlobalWriteACP() || Lookups.checkPrivilege(PolicySpec.S3_PUTOBJECTACL, PolicySpec.VENDOR_S3, PolicySpec.S3_RESOURCE_OBJECT, PolicySpec.objectFullName(destinationBucket, destinationKey), null)))) { List<GrantInfo> grantInfos = new ArrayList<GrantInfo>(); destinationObjectInfo.addGrants(account.getAccountNumber(), foundDestinationBucketInfo.getOwnerId(), grantInfos, accessControlList); destinationObjectInfo.setGrants(grantInfos); } destinationObjectOldSize = destinationObjectInfo.getSize() == null ? 0L : destinationObjectInfo.getSize(); } destinationObjectInfo.setSize(sourceObjectInfo.getSize()); destinationObjectInfo.setStorageClass(sourceObjectInfo.getStorageClass()); destinationObjectInfo.setOwnerId(sourceObjectInfo.getOwnerId()); destinationObjectInfo.setContentType(sourceObjectInfo.getContentType()); destinationObjectInfo.setContentDisposition(sourceObjectInfo.getContentDisposition()); String etag = sourceObjectInfo.getEtag(); Date lastModified = sourceObjectInfo.getLastModified(); destinationObjectInfo.setEtag(etag); destinationObjectInfo.setLastModified(lastModified); destinationObjectInfo.setVersionId(destinationVersionId); destinationObjectInfo.setLast(true); destinationObjectInfo.setDeleted(false); if (!metadataDirective.equals("REPLACE")) { destinationObjectInfo.setMetaData(sourceObjectInfo.cloneMetaData()); } else { List<MetaDataEntry> metaData = request.getMetaData(); if (metaData != null) destinationObjectInfo.replaceMetaData(metaData); } String sourceObjectName = sourceObjectInfo.getObjectName(); destinationObjectName = destinationObjectInfo.getObjectName(); try { storageManager.copyObject(sourceBucket, sourceObjectName, destinationBucket, destinationObjectName); } catch (Exception ex) { LOG.error(ex); db.rollback(); throw new EucalyptusCloudException( "Could not rename " + sourceObjectName + " to " + destinationObjectName); } if (addNew) dbObject.add(destinationObjectInfo); reply.setEtag(etag); reply.setLastModified( DateUtils.format(lastModified.getTime(), DateUtils.ALT_ISO8601_DATE_PATTERN)); if (foundDestinationBucketInfo.isVersioningEnabled()) { reply.setCopySourceVersionId(sourceVersionId); reply.setVersionId(destinationVersionId); } db.commit(); try { // Fixes EUCA-3756. Reporting event for copy // objects fireObjectCreationEvent(destinationBucket, destinationObjectName, destinationVersionId, ctx.getUser().getUserId(), destinationObjectInfo.getSize(), destinationObjectOldSize); } catch (Exception ex) { LOG.debug("Failed to fire reporting event for walrus COPY object operation", ex); } return reply; } else { db.rollback(); throw new AccessDeniedException("Bucket", destinationBucket); } } else { db.rollback(); throw new NoSuchBucketException(destinationBucket); } } else { db.rollback(); throw new AccessDeniedException("Key", sourceKey); } } else { db.rollback(); throw new NoSuchEntityException(sourceKey); } } else { db.rollback(); throw new NoSuchBucketException(sourceBucket); } }
From source file:com.google.bitcoin.core.Wallet.java
private void removeEntriesAfterDate(Map<Sha256Hash, Transaction> pool, Date fromDate) { checkState(lock.isLocked());//from www .j a v a 2 s.com log.debug("Wallet#removeEntriesAfterDate - Removing transactions later than " + fromDate.toString()); Set<Entry<Sha256Hash, Transaction>> loopEntries = pool.entrySet(); Iterator<Entry<Sha256Hash, Transaction>> iterator = loopEntries.iterator(); while (iterator.hasNext()) { Entry<Sha256Hash, Transaction> member = iterator.next(); if (member.getValue() != null) { Date updateTime = member.getValue().getUpdateTime(); if (updateTime != null && updateTime.after(fromDate)) { iterator.remove(); //log.debug("Wallet#removeEntriesAfterDate - Removed tx.1 " + member.getValue()); continue; } // if no updateTime remove them if (updateTime == null || updateTime.getTime() == 0) { iterator.remove(); //log.debug("Removed tx.2 " + member.getValue()); continue; } } } }
From source file:edu.ucsb.eucalyptus.cloud.ws.WalrusManager.java
public CopyObjectResponseType copyObject(CopyObjectType request) throws EucalyptusCloudException { CopyObjectResponseType reply = (CopyObjectResponseType) request.getReply(); String userId = request.getUserId(); String sourceBucket = request.getSourceBucket(); String sourceKey = request.getSourceObject(); String sourceVersionId = request.getSourceVersionId(); String destinationBucket = request.getDestinationBucket(); String destinationKey = request.getDestinationObject(); String metadataDirective = request.getMetadataDirective(); AccessControlListType accessControlList = request.getAccessControlList(); String copyIfMatch = request.getCopySourceIfMatch(); String copyIfNoneMatch = request.getCopySourceIfNoneMatch(); Date copyIfUnmodifiedSince = request.getCopySourceIfUnmodifiedSince(); Date copyIfModifiedSince = request.getCopySourceIfModifiedSince(); if (metadataDirective == null) metadataDirective = "COPY"; EntityWrapper<BucketInfo> db = WalrusControl.getEntityWrapper(); BucketInfo bucketInfo = new BucketInfo(sourceBucket); List<BucketInfo> bucketList = db.query(bucketInfo); if (bucketList.size() > 0) { EntityWrapper<ObjectInfo> dbObject = db.recast(ObjectInfo.class); ObjectInfo searchObjectInfo = new ObjectInfo(sourceBucket, sourceKey); searchObjectInfo.setVersionId(sourceVersionId); if (sourceVersionId == null) searchObjectInfo.setLast(true); List<ObjectInfo> objectInfos = dbObject.query(searchObjectInfo); if (objectInfos.size() > 0) { ObjectInfo sourceObjectInfo = objectInfos.get(0); if (sourceObjectInfo.canRead(userId)) { if (copyIfMatch != null) { if (!copyIfMatch.equals(sourceObjectInfo.getEtag())) { db.rollback();/*from w w w .j a v a 2 s . c om*/ throw new PreconditionFailedException(sourceKey + " CopySourceIfMatch: " + copyIfMatch); } } if (copyIfNoneMatch != null) { if (copyIfNoneMatch.equals(sourceObjectInfo.getEtag())) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfNoneMatch: " + copyIfNoneMatch); } } if (copyIfUnmodifiedSince != null) { long unmodifiedTime = copyIfUnmodifiedSince.getTime(); long objectTime = sourceObjectInfo.getLastModified().getTime(); if (unmodifiedTime < objectTime) { db.rollback(); throw new PreconditionFailedException(sourceKey + " CopySourceIfUnmodifiedSince: " + copyIfUnmodifiedSince.toString()); } } if (copyIfModifiedSince != null) { long modifiedTime = copyIfModifiedSince.getTime(); long objectTime = sourceObjectInfo.getLastModified().getTime(); if (modifiedTime > objectTime) { db.rollback(); throw new PreconditionFailedException( sourceKey + " CopySourceIfModifiedSince: " + copyIfModifiedSince.toString()); } } BucketInfo destinationBucketInfo = new BucketInfo(destinationBucket); List<BucketInfo> destinationBuckets = db.query(destinationBucketInfo); if (destinationBuckets.size() > 0) { BucketInfo foundDestinationBucketInfo = destinationBuckets.get(0); if (foundDestinationBucketInfo.canWrite(userId)) { // all ok String destinationVersionId = sourceVersionId; ObjectInfo destinationObjectInfo = null; String destinationObjectName; ObjectInfo destSearchObjectInfo = new ObjectInfo(destinationBucket, destinationKey); if (foundDestinationBucketInfo.isVersioningEnabled()) { if (sourceVersionId != null) destinationVersionId = sourceVersionId; else destinationVersionId = UUID.randomUUID().toString().replaceAll("-", ""); } else { destinationVersionId = WalrusProperties.NULL_VERSION_ID; } destSearchObjectInfo.setVersionId(destinationVersionId); List<ObjectInfo> destinationObjectInfos = dbObject.query(destSearchObjectInfo); if (destinationObjectInfos.size() > 0) { destinationObjectInfo = destinationObjectInfos.get(0); if (!destinationObjectInfo.canWrite(userId)) { db.rollback(); throw new AccessDeniedException("Key", destinationKey); } } boolean addNew = false; if (destinationObjectInfo == null) { // not found. create a new one addNew = true; destinationObjectInfo = new ObjectInfo(); List<GrantInfo> grantInfos = new ArrayList<GrantInfo>(); destinationObjectInfo.setBucketName(destinationBucket); destinationObjectInfo.setObjectKey(destinationKey); destinationObjectInfo.addGrants(userId, grantInfos, accessControlList); destinationObjectInfo.setGrants(grantInfos); destinationObjectInfo.setObjectName(UUID.randomUUID().toString()); } else { if (destinationObjectInfo.canWriteACP(userId)) { List<GrantInfo> grantInfos = new ArrayList<GrantInfo>(); destinationObjectInfo.addGrants(userId, grantInfos, accessControlList); destinationObjectInfo.setGrants(grantInfos); } } destinationObjectInfo.setSize(sourceObjectInfo.getSize()); destinationObjectInfo.setStorageClass(sourceObjectInfo.getStorageClass()); destinationObjectInfo.setOwnerId(sourceObjectInfo.getOwnerId()); destinationObjectInfo.setContentType(sourceObjectInfo.getContentType()); destinationObjectInfo.setContentDisposition(sourceObjectInfo.getContentDisposition()); String etag = sourceObjectInfo.getEtag(); Date lastModified = sourceObjectInfo.getLastModified(); destinationObjectInfo.setEtag(etag); destinationObjectInfo.setLastModified(lastModified); destinationObjectInfo.setVersionId(destinationVersionId); destinationObjectInfo.setLast(true); destinationObjectInfo.setDeleted(false); if (!metadataDirective.equals("REPLACE")) { destinationObjectInfo.setMetaData(sourceObjectInfo.cloneMetaData()); } else { List<MetaDataEntry> metaData = request.getMetaData(); if (metaData != null) destinationObjectInfo.replaceMetaData(metaData); } String sourceObjectName = sourceObjectInfo.getObjectName(); destinationObjectName = destinationObjectInfo.getObjectName(); try { storageManager.copyObject(sourceBucket, sourceObjectName, destinationBucket, destinationObjectName); if (WalrusProperties.trackUsageStatistics) walrusStatistics.updateSpaceUsed(sourceObjectInfo.getSize()); } catch (Exception ex) { LOG.error(ex); db.rollback(); throw new EucalyptusCloudException( "Could not rename " + sourceObjectName + " to " + destinationObjectName); } if (addNew) dbObject.add(destinationObjectInfo); // get rid of delete marker ObjectInfo deleteMarker = new ObjectInfo(destinationBucket, destinationKey); deleteMarker.setDeleted(true); try { ObjectInfo foundDeleteMarker = dbObject.getUnique(deleteMarker); dbObject.delete(foundDeleteMarker); } catch (EucalyptusCloudException ex) { // no delete marker found. LOG.trace( "No delete marker found for: " + destinationBucket + "/" + destinationKey); } reply.setEtag(etag); reply.setLastModified( DateUtils.format(lastModified.getTime(), DateUtils.ISO8601_DATETIME_PATTERN) + ".000Z"); if (foundDestinationBucketInfo.isVersioningEnabled()) { reply.setCopySourceVersionId(sourceVersionId); reply.setVersionId(destinationVersionId); } db.commit(); return reply; } else { db.rollback(); throw new AccessDeniedException("Bucket", destinationBucket); } } else { db.rollback(); throw new NoSuchBucketException(destinationBucket); } } else { db.rollback(); throw new AccessDeniedException("Key", sourceKey); } } else { db.rollback(); throw new NoSuchEntityException(sourceKey); } } else { db.rollback(); throw new NoSuchBucketException(sourceBucket); } }
From source file:com.google.bitcoin.core.Wallet.java
/** * Formats the wallet as a human readable piece of text. Intended for debugging, the format is not meant to be * stable or human readable.//from w w w. j ava2s .com * @param includePrivateKeys Whether raw private key data should be included. * @param includeTransactions Whether to print transaction data. * @param includeExtensions Whether to print extension data. * @param chain If set, will be used to estimate lock times for block timelocked transactions. */ public String toString(boolean includePrivateKeys, boolean includeTransactions, boolean includeExtensions, @Nullable AbstractBlockChain chain) { lock.lock(); try { StringBuilder builder = new StringBuilder(); BigInteger estimatedBalance = getBalance(BalanceType.ESTIMATED); BigInteger availableBalance = getBalance(BalanceType.AVAILABLE); builder.append(String.format("Wallet containing %s BTC (available: %s BTC) in:%n", bitcoinValueToPlainString(estimatedBalance), bitcoinValueToPlainString(availableBalance))); builder.append(String.format(" %d pending transactions%n", pending.size())); builder.append(String.format(" %d unspent transactions%n", unspent.size())); builder.append(String.format(" %d spent transactions%n", spent.size())); builder.append(String.format(" %d dead transactions%n", dead.size())); final Date lastBlockSeenTime = getLastBlockSeenTime(); final String lastBlockSeenTimeStr = lastBlockSeenTime == null ? "time unknown" : lastBlockSeenTime.toString(); builder.append(String.format("Last seen best block: %d (%s): %s%n", getLastBlockSeenHeight(), lastBlockSeenTimeStr, getLastBlockSeenHash())); if (this.keyCrypter != null) { builder.append(String.format("Encryption: %s%n", keyCrypter.toString())); } // Do the keys. builder.append("\nKeys:\n"); for (ECKey key : keychain) { final Address address = key.toAddress(params); builder.append(" addr:"); builder.append(address.toString()); builder.append(" hash160:"); builder.append(Utils.bytesToHexString(address.getHash160())); builder.append(" "); builder.append(includePrivateKeys ? key.toStringWithPrivate() : key.toString()); builder.append("\n"); } if (!watchedScripts.isEmpty()) { builder.append("\nWatched scripts:\n"); for (Script script : watchedScripts) { builder.append(" "); builder.append(script.toString()); builder.append("\n"); } } if (includeTransactions) { // Print the transactions themselves if (pending.size() > 0) { builder.append("\n>>> PENDING:\n"); toStringHelper(builder, pending, chain, SORT_ORDER_BY_UPDATE_TIME); } if (unspent.size() > 0) { builder.append("\n>>> UNSPENT:\n"); toStringHelper(builder, unspent, chain, SORT_ORDER_BY_HEIGHT); } if (spent.size() > 0) { builder.append("\n>>> SPENT:\n"); toStringHelper(builder, spent, chain, SORT_ORDER_BY_HEIGHT); } if (dead.size() > 0) { builder.append("\n>>> DEAD:\n"); toStringHelper(builder, dead, chain, SORT_ORDER_BY_HEIGHT); } } if (includeExtensions && extensions.size() > 0) { builder.append("\n>>> EXTENSIONS:\n"); for (WalletExtension extension : extensions.values()) { builder.append(extension).append("\n\n"); } } return builder.toString(); } finally { lock.unlock(); } }
From source file:com.gloriouseggroll.LastFMAPI.java
@SuppressWarnings({ "null", "SleepWhileInLoop", "UseSpecificCatch" }) private JSONObject GetData(request_type type, String url, String post) { Date start = new Date(); Date preconnect = start;/*from w w w . j a v a2 s.c om*/ Date postconnect = start; Date prejson = start; Date postjson = start; JSONObject j = new JSONObject("{}"); BufferedInputStream i = null; String rawcontent = ""; int available = 0; int responsecode = 0; long cl = 0; try { URL u = new URL(url); HttpsURLConnection c = (HttpsURLConnection) u.openConnection(); c.setRequestMethod(type.name()); c.setUseCaches(false); c.setDefaultUseCaches(false); c.setConnectTimeout(5000); c.setReadTimeout(5000); c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36 QuorraBot/2015"); c.setRequestProperty("Content-Type", "application/json-rpc"); c.setRequestProperty("Content-length", "0"); if (!post.isEmpty()) { c.setDoOutput(true); } preconnect = new Date(); c.connect(); postconnect = new Date(); if (!post.isEmpty()) { try (BufferedOutputStream o = new BufferedOutputStream(c.getOutputStream())) { IOUtils.write(post, o); } } String content; cl = c.getContentLengthLong(); responsecode = c.getResponseCode(); if (c.getResponseCode() == 200) { i = new BufferedInputStream(c.getInputStream()); } else { i = new BufferedInputStream(c.getErrorStream()); } /* * if (i != null) { available = i.available(); * * while (available == 0 && (new Date().getTime() - * postconnect.getTime()) < 450) { Thread.sleep(500); available = * i.available(); } * * if (available == 0) { i = new * BufferedInputStream(c.getErrorStream()); * * if (i != null) { available = i.available(); } } } * * if (available == 0) { content = "{}"; } else { content = * IOUtils.toString(i, c.getContentEncoding()); } */ content = IOUtils.toString(i, c.getContentEncoding()); rawcontent = content; prejson = new Date(); j = new JSONObject(content); j.put("_success", true); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", c.getResponseCode()); j.put("_available", available); j.put("_exception", ""); j.put("_exceptionMessage", ""); j.put("_content", content); postjson = new Date(); } catch (JSONException ex) { if (ex.getMessage().contains("A JSONObject text must begin with")) { j = new JSONObject("{}"); j.put("_success", true); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "MalformedJSONData (HTTP " + responsecode + ")"); j.put("_exceptionMessage", ""); j.put("_content", rawcontent); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } catch (MalformedURLException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "MalformedURLException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (SocketTimeoutException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "SocketTimeoutException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (IOException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "IOException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (Exception ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "Exception [" + ex.getClass().getName() + "]"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } if (i != null) { try { i.close(); } catch (IOException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "IOException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } } if (Quorrabot.enableDebugging) { com.gmt2001.Console.out.println(">>>[DEBUG] LastFMAPI.GetData Timers " + (preconnect.getTime() - start.getTime()) + " " + (postconnect.getTime() - start.getTime()) + " " + (prejson.getTime() - start.getTime()) + " " + (postjson.getTime() - start.getTime()) + " " + start.toString() + " " + postjson.toString()); com.gmt2001.Console.out.println(">>>[DEBUG] LastFMAPI.GetData Exception " + j.getString("_exception") + " " + j.getString("_exceptionMessage")); com.gmt2001.Console.out.println(">>>[DEBUG] LastFMAPI.GetData HTTP/Available " + j.getInt("_http") + "(" + responsecode + ")/" + j.getInt("_available") + "(" + cl + ")"); com.gmt2001.Console.out.println(">>>[DEBUG] LastFMAPI.GetData RawContent[0,100] " + j.getString("_content").substring(0, Math.min(100, j.getString("_content").length()))); } return j; }
From source file:gov.llnl.lustre.lwatch.PlotFrame2.java
/** * Update the control widgets to reflect the current time settings. *///from w w w . ja va2 s. c om public void updateControlValues() { int tindx = ovIDX / nCurvesSelected; int[] daysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; //long xstart = rawTimes[tindx][startIndex]; //long xstop = rawTimes[tindx][stopIndex]; /*** if (localDebug) { Debug.out("\nxstart before = " + (new Date(xstart)).toString() + " stopIndex = " + startIndex); Debug.out("xstop before = " + (new Date(xstop)).toString() + " stopIndex = " + stopIndex); } if (xstop < (3600000*48)) { // Invalid time value while ((stopIndex > 0) && ((rawTimes[ovIDX][stopIndex]) < (3600000*48))) { if (localDebug) Debug.out(stopIndex + " " + xstop); xstop = rawTimes[tindx][--stopIndex]; } } ***/ if (limitedDebug) { Debug.out("dataPointCount[0] = " + dataPointCount[0]); Debug.out("tsStartPlot after = " + tsStartPlot); Debug.out("tsEndPlot after = " + tsEndPlot + "\n"); } Date dstart = new Date(tsStartPlot.getTime()); //xstart); Date dstop = new Date(tsEndPlot.getTime()); //xstop); GregorianCalendar cal = new GregorianCalendar(); if (localDebug) Debug.out("dstart = " + dstart.toString() + "\ndstop = " + dstop.toString()); // Set the Start widgets. cal.setTime(dstart); int yrstart = cal.get(Calendar.YEAR); yrChooser.setSelectedYear(yrstart); int mnthstart = cal.get(Calendar.MONTH); monthChooser.setSelectedMonth(mnthstart); int daystart = cal.get(Calendar.DAY_OF_MONTH); dayChooser.setSelectedDay(daystart); int hrstart = cal.get(Calendar.HOUR_OF_DAY); hourChooser.setSelectedHour(hrstart); int minstart = cal.get(Calendar.MINUTE); minuteChooser.setSelectedMinute(minstart); // Set the End widgets. cal.setTime(dstop); int yrstop = cal.get(Calendar.YEAR); yrEndChooser.setSelectedYear(yrstop); int mnthstop = cal.get(Calendar.MONTH); monthEndChooser.setSelectedMonth(mnthstop); int daystop = cal.get(Calendar.DAY_OF_MONTH); dayEndChooser.setSelectedDay(daystop); int hrstop = cal.get(Calendar.HOUR_OF_DAY); hourEndChooser.setSelectedHour(hrstop); int minstop = cal.get(Calendar.MINUTE); minuteEndChooser.setSelectedMinute(minstop); // Set the Duration widgets. long durationhours = (tsEndPlot.getTime() - tsStartPlot.getTime()) / HOUR; //Debug.out("Length of chart plot interval = " + durationhours + " hours"); int yrDur = yrstop - yrstart; //Debug.out("yrDur = " + yrDur); int mnthDur = mnthstop - mnthstart; //Debug.out("mnthDur = " + mnthDur); if (mnthDur < 0) { yrDur = Math.max(0, yrDur - 1); mnthDur = 12 - mnthstart + mnthstop; //Debug.out("Adjusted mnthDur = " + mnthDur); } int dayDur = daystop - daystart; //Debug.out("dayDur = " + dayDur); if (dayDur < 0) { mnthDur = Math.max(0, mnthDur - 1); dayDur = daysInMonth[mnthstart] - daystart + daystop; //Debug.out("Adjusted dayDur = " + dayDur); } int hrDur = hrstop - hrstart; //Debug.out("hrDur = " + hrDur); if (hrDur < 0) { dayDur = Math.max(0, dayDur - 1); hrDur = 24 - hrstart + hrstop; //Debug.out("Adjusted hrDur = " + hrDur); } int minDur = minstop - minstart; //Debug.out("minDur = " + minDur + "\n"); if (minDur < 0) { hrDur = Math.max(0, hrDur - 1); minDur = 60 - minstart + minstop; //Debug.out("Adjusted minDur = " + minDur + "\n"); } yrDurChooser.setSelected(yrDur); monthDurChooser.setSelected(mnthDur); dayDurChooser.setSelected(dayDur); hourDurChooser.setSelected(hrDur); minuteDurChooser.setSelected(minDur); }
From source file:com.gloriouseggroll.DonationHandlerAPI.java
@SuppressWarnings({ "null", "SleepWhileInLoop", "UseSpecificCatch" }) private JSONObject GetData(request_type type, String url, String post) { Date start = new Date(); Date preconnect = start;//w ww.jav a 2 s .com Date postconnect = start; Date prejson = start; Date postjson = start; JSONObject j = new JSONObject("{}"); BufferedInputStream i = null; String rawcontent = ""; int available = 0; int responsecode = 0; long cl = 0; try { URL u = new URL(url); HttpsURLConnection c = (HttpsURLConnection) u.openConnection(); c.setRequestMethod(type.name()); c.setUseCaches(false); c.setDefaultUseCaches(false); c.setConnectTimeout(5000); c.setReadTimeout(5000); c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36 QuorraBot/2015"); c.setRequestProperty("Content-Type", "application/json-rpc"); c.setRequestProperty("Content-length", "0"); if (!post.isEmpty()) { c.setDoOutput(true); } preconnect = new Date(); c.connect(); postconnect = new Date(); if (!post.isEmpty()) { try (BufferedOutputStream o = new BufferedOutputStream(c.getOutputStream())) { IOUtils.write(post, o); } } String content; cl = c.getContentLengthLong(); responsecode = c.getResponseCode(); if (c.getResponseCode() == 200) { i = new BufferedInputStream(c.getInputStream()); } else { i = new BufferedInputStream(c.getErrorStream()); } /* * if (i != null) { available = i.available(); * * while (available == 0 && (new Date().getTime() - * postconnect.getTime()) < 450) { Thread.sleep(500); available = * i.available(); } * * if (available == 0) { i = new * BufferedInputStream(c.getErrorStream()); * * if (i != null) { available = i.available(); } } } * * if (available == 0) { content = "{}"; } else { content = * IOUtils.toString(i, c.getContentEncoding()); } */ content = IOUtils.toString(i, c.getContentEncoding()); rawcontent = content; prejson = new Date(); j = new JSONObject(content); j.put("_success", true); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", c.getResponseCode()); j.put("_available", available); j.put("_exception", ""); j.put("_exceptionMessage", ""); j.put("_content", content); postjson = new Date(); } catch (JSONException ex) { if (ex.getMessage().contains("A JSONObject text must begin with")) { j = new JSONObject("{}"); j.put("_success", true); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "MalformedJSONData (HTTP " + responsecode + ")"); j.put("_exceptionMessage", ""); j.put("_content", rawcontent); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } catch (MalformedURLException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "MalformedURLException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (SocketTimeoutException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "SocketTimeoutException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (IOException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "IOException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (Exception ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "Exception [" + ex.getClass().getName() + "]"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } if (i != null) { try { i.close(); } catch (IOException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "IOException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (Quorrabot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } } if (Quorrabot.enableDebugging) { com.gmt2001.Console.out.println(">>>[DEBUG] DonationHandlerAPI.GetData Timers " + (preconnect.getTime() - start.getTime()) + " " + (postconnect.getTime() - start.getTime()) + " " + (prejson.getTime() - start.getTime()) + " " + (postjson.getTime() - start.getTime()) + " " + start.toString() + " " + postjson.toString()); com.gmt2001.Console.out.println(">>>[DEBUG] DonationHandlerAPI.GetData Exception " + j.getString("_exception") + " " + j.getString("_exceptionMessage")); com.gmt2001.Console.out.println(">>>[DEBUG] DonationHandlerAPI.GetData HTTP/Available " + j.getInt("_http") + "(" + responsecode + ")/" + j.getInt("_available") + "(" + cl + ")"); com.gmt2001.Console.out.println(">>>[DEBUG] DonationHandlerAPI.GetData RawContent[0,100] " + j.getString("_content").substring(0, Math.min(100, j.getString("_content").length()))); } return j; }
From source file:MiGA.StatsSelection.java
public void getImPerfectCompoundSSRs(String[] organisms, int length, boolean flag, int gap) throws SQLException, ClassNotFoundException, FileNotFoundException, IOException { String statsfile = ""; for (int i = 0; i < organisms.length; i++) { boolean found = false; String buffer = new String(); int seekstart = 0; int seekend = 0; List<String> ssrs = new ArrayList<String>(); // 18/11/2013 added starting here String filetype = ""; String filepro = ""; if (flag) { filetype = "organisms"; filepro = "organisms/" + organisms[i] + "/data/"; int ret = getOrganismStatus(organisms[i]); if (ret == -1) indexer = new Indexer(chromosomelist); else/*from www . j a va2 s. c om*/ indexer = new Indexer(ret); } else { filetype = "local"; filepro = "local/" + organisms[i] + "/data/"; String indexfile = "local/" + organisms[i] + "/index.txt"; indexer = new Indexer(indexfile); } //List<String> files = getFiles(organisms[i], minlen, flag); // 18/11/2013 added ending here PrintWriter out; PrintWriter stats; PrintWriter html; DataOutputStream lt = null; if (filetype.contains("organism")) { File f = new File("organisms/" + organisms[i] + "/stats/"); if (!f.exists()) { f.mkdir(); } stats = new PrintWriter( new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true)); lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("organisms/" + organisms[i] + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compim"))); html = new PrintWriter(new FileWriter("organisms/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".html", true)); File fi = new File("organisms/" + organisms[i] + "/results/"); if (!fi.exists()) { fi.mkdir(); } String toopen = "organisms/" + organisms[i] + "/results/allCompImPerfect_" + now.toString().replace(':', '_').replace(' ', '_') + ".txt"; statsfile = toopen; out = new PrintWriter(toopen); out.println("Results for organism: " + organisms[i] + "\t Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap + " - minimum SSR length(bp): " + length); } else { File f = new File("local/" + organisms[i] + "/stats/"); if (!f.exists()) { f.mkdir(); } stats = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".txt", true)); lt = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("local/" + organisms[i] + "/data/" + now.toString().replace(':', '_').replace(' ', '_') + ".compim"))); html = new PrintWriter(new FileWriter("local/" + organisms[i] + "/stats/" + "summary_statistics" + now.toString().replace(':', '_').replace(' ', '_') + ".html", true)); File fi = new File("local/" + organisms[i] + "/results/"); if (!fi.exists()) { fi.mkdir(); } Calendar calendar = Calendar.getInstance(); Date now = calendar.getTime(); String toopen = "local/" + organisms[i] + "/results/allCompImPerfect_" + now.toString().replace(':', '_').replace(' ', '_') + ".txt"; statsfile = toopen; out = new PrintWriter(toopen); out.println("Results for project: " + organisms[i] + "\t Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap + " - minimum SSR length(bp): " + length); } int countpc = 0; int bpcount = 0, Aperc = 0, Tperc = 0, Gperc = 0, Cperc = 0; while (indexer.hasNext()) { String files = filepro + indexer.getNextFileName(); DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files))); //PrintWriter out = new PrintWriter(files + "-minlentgh_" + length + "_ImPerfect.stats"); boolean eof = false; while (!eof) { try { SSR = new ArrayList<String>(); repeats = new ArrayList<Integer>(); EndOfSsr = new ArrayList<Integer>(); start = new ArrayList<Integer>(); int len = in.readInt(); int line = in.readInt(); for (int k = 0; k < len; k++) { //THIS String temp = in.readUTF(); if (!temp.contains("N")) { SSR.add(temp); EndOfSsr.add(in.readInt()); repeats.add(in.readInt()); start.add(EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k))); } else { int junk = in.readInt(); junk = in.readInt(); } } List<String> SSRlen = new ArrayList<String>(); List<Integer> Endlen = new ArrayList<Integer>(); List<Integer> repslen = new ArrayList<Integer>(); List<Integer> startlen = new ArrayList<Integer>(); for (int k = 0; k < SSR.size(); k++) { if (SSR.get(k).length() * repeats.get(k) >= length) { SSRlen.add(SSR.get(k)); Endlen.add(EndOfSsr.get(k)); repslen.add(repeats.get(k)); startlen.add(start.get(k)); } } List<Integer> sortedstart = new ArrayList<Integer>(); List<Integer> sortedend = new ArrayList<Integer>(); for (int t = 0; t < startlen.size(); t++) { sortedstart.add(startlen.get(t)); sortedend.add(Endlen.get(t)); } Collections.sort(sortedstart); Collections.sort(sortedend); //List<String> tofile = new ArrayList<String>(); for (int k = 0; k < sortedstart.size() - 2; k++) { found = false; ssrs.clear(); ssrs = new ArrayList<String>(); if (sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { seekstart = sortedstart.get(k); while (k < sortedstart.size() - 1 && sortedstart.get(k + 1) - sortedend.get(k) <= gap && sortedstart.get(k + 1) - sortedend.get(k) >= 0) { for (int c = 0; c < startlen.size(); c++) { if (sortedstart.get(k) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); } if (sortedstart.get(k + 1) == startlen.get(c)) { ssrs.add(SSRlen.get(c)); seekend = Endlen.get(c); found = true; } } k++; } k--; } boolean check = checkallsame(ssrs); boolean check2 = checkalldiff(ssrs); if (found && !check && !check2) { BufferedReader stdin = null; if (flag) { String[] temp = files.split("/"); boolean type = CheckForKaryotype(organisms[i]); String newdir = ""; if (type) { newdir = temp[0] + "/" + temp[1] + "/chrom-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + "-slices.txt"; } else { newdir = temp[0] + "/" + temp[1] + "/slice-" + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt"; } stdin = new BufferedReader(new FileReader(newdir)); } else { String[] temp = files.split("data/"); String newdir = temp[0] + "/" + temp[1].substring(0, temp[1].lastIndexOf('.')) + ".txt"; stdin = new BufferedReader(new FileReader(newdir)); } buffer = ""; for (int c = 0; c < line; c++) { buffer = stdin.readLine(); } //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend); int real_end = (line - 1) * 20000 + seekend; int real_start = (line - 1) * 20000 + seekstart; //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end ); countpc++; if (seekstart < 0) seekstart++; String tmp = buffer.substring(seekstart, seekend); bpcount += tmp.length(); if (tmp.contains("A")) { Aperc += StringUtils.countMatches(tmp, "A"); } if (tmp.contains("T")) { Tperc += StringUtils.countMatches(tmp, "T"); } if (tmp.contains("G")) { Gperc += StringUtils.countMatches(tmp, "G"); } if (tmp.contains("C")) { Cperc += StringUtils.countMatches(tmp, "C"); } out.println("SSR: " + tmp + " start-end: " + real_start + "-" + real_end + " Path(../data/chromosome): " + files.substring(0, files.lastIndexOf('.'))); stdin.close(); } } } catch (EOFException e) { eof = true; } } in.close(); } out.close(); Runtime.getRuntime().exec("notepad " + statsfile); try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } Connection con = null; try { con = DriverManager.getConnection("jdbc:mysql://localhost:3306", "biouser", "thesis2012"); } catch (SQLException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } Statement st = null; try { st = con.createStatement(); } catch (SQLException ex) { Logger.getLogger(StatsSelection.class.getName()).log(Level.SEVERE, null, ex); } st.executeUpdate("use lobid"); int seqcount = 0; if (filetype.contains("organisms")) { ResultSet rs = st.executeQuery( "SELECT end FROM slices INNER JOIN organism WHERE slices.org_id=organism.org_id AND organism.name='" + organisms[i] + "'"); while (rs.next()) { seqcount += Long.parseLong(rs.getString(1)); } } else if (filetype.contains("local")) { BufferedReader in = new BufferedReader(new FileReader("local/" + organisms[i] + "/index.txt")); int count = countlines("local/" + organisms[i] + "/index.txt"); for (int c = 0; c < count; c++) { String temp = in.readLine(); BufferedReader tmp = new BufferedReader( new FileReader("local/" + organisms[i] + "/" + temp + ".txt")); boolean eof = false; while (!eof) { String s = tmp.readLine(); if (s != null) { seqcount += s.length(); } else { eof = true; } } tmp.close(); } } DecimalFormat round = new DecimalFormat("#.###"); html.println("<html><h1>******* Compound Imperfect SSRs *******</h1>"); html.println("<h4>Results for project: " + organisms[i] + "</h4><h4>Search Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs (bp) : " + gap + "</h4><h4>minimum SSR length (bp): " + length + "</h4>"); html.println( "<table border=\"1\"><tr><td> </td><td><b>count</b></td><td><b>bp</b></td><td><b>A%</b></td><td><b>T%</b></td><td><b>C%</b></td><td><b>G%</b></td><td><b>Relative Frequency</b></td><td><b>Abundance</b></td><td><b>Relative Abundance</b></td></tr>"); html.println("<tr><td><b>Compound Imperf.</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>" + round.format((float) Aperc * 100 / bpcount) + "</td><td>" + round.format((float) Tperc * 100 / bpcount) + "</td><td>" + round.format((float) Cperc * 100 / bpcount) + "</td><td>" + round.format((float) Gperc * 100 / bpcount) + "</td><td>" + round.format((float) countpc / countpc) + "</td><td>" + round.format((float) bpcount / seqcount) + "</td><td>" + round.format((float) bpcount / bpcount) + "</td></tr>"); html.println("<tr><td><b>TOTAL</b></td><td>" + countpc + "</td><td>" + bpcount + "</td><td>" + round.format((float) Aperc * 100 / bpcount) + "</td><td>" + round.format((float) Tperc * 100 / bpcount) + "</td><td>" + round.format((float) Cperc * 100 / bpcount) + "</td><td>" + round.format((float) Gperc * 100 / bpcount) + "</td><td>" + round.format((float) countpc / countpc) + "</td><td>" + round.format((float) bpcount / seqcount) + "</td><td>" + round.format((float) bpcount / bpcount) + "</td></tr></table></html>"); html.close(); stats.println("******* Compound Imperfect SSRs *******"); stats.println("Results for project: " + organisms[i] + "\nSearch Parameters --> Maximum Inter-repeat Region for Imperfect Compound SSRs(bp) : " + gap + "\nminimum SSR length(bp): " + length); stats.println( " ____________________________________________________________________________________________________________________ "); stats.println( "| | | | | | | | Relative | | Relative |"); stats.println( "| | count | bp | A% | T% | C% | G% | Frequency | Abundance | Abundance |"); stats.println( "|===============|=======|============|=======|=======|=======|=======|===============|===============|===============|"); stats.printf( "|Compound Imper.|" + cell(Integer.toString(countpc), 7) + "|" + cell(Integer.toString(bpcount), 12) + "|%s|%s|%s|%s|" + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|\n", cell((float) Aperc * 100 / bpcount, 7), cell((float) Tperc * 100 / bpcount, 7), cell((float) Cperc * 100 / bpcount, 7), cell((float) Gperc * 100 / bpcount, 7)); stats.println( "|---------------|-------|------------|-------|-------|-------|-------|---------------|---------------|---------------|"); lt.writeLong(seqcount); lt.writeInt(countpc); lt.writeInt(bpcount); lt.writeInt(Aperc); lt.writeInt(Tperc); lt.writeInt(Gperc); lt.writeInt(Cperc); stats.println("|TOTAL |" + cell(Integer.toString(countpc), 7) + "|" + cell(Long.toString(bpcount), 12) + "|" + cell((float) Aperc * 100 / bpcount, 7) + "|" + cell((float) Tperc * 100 / bpcount, 7) + "|" + cell((float) Cperc * 100 / bpcount, 7) + "|" + cell((float) Gperc * 100 / bpcount, 7) + "|" + cell((float) countpc / countpc, 15) + "|" + cell((float) bpcount / seqcount, 15) + "|" + cell((float) bpcount / bpcount, 15) + "|"); stats.println( "|_______________|_______|____________|_______|_______|_______|_______|_______________|_______________|_______________|"); stats.println("Genome length (bp): " + seqcount); stats.println("Relative Frequency: Count of each motif type / total SSR count"); stats.println("Abundance: bp of each motif type / total sequence bp"); stats.println("Relative Abundance: bp of each motif type / total microsatellites bp"); stats.println(); stats.println(); stats.close(); lt.close(); } }
From source file:com.gmt2001.YouTubeAPIv3.java
@SuppressWarnings({ "null", "SleepWhileInLoop", "UseSpecificCatch" }) private JSONObject GetData(request_type type, String url, String post) { Date start = new Date(); Date preconnect = start;//from w w w .ja va 2 s . c om Date postconnect = start; Date prejson = start; Date postjson = start; JSONObject j = new JSONObject("{}"); BufferedInputStream i = null; String rawcontent = ""; int available = 0; int responsecode = 0; long cl = 0; try { if (url.contains("?") && !url.contains("oembed?")) { url += "&utcnow=" + System.currentTimeMillis(); } else { if (!url.contains("oembed?")) { url += "?utcnow=" + System.currentTimeMillis(); } } URL u = new URL(url); HttpsURLConnection c = (HttpsURLConnection) u.openConnection(); c.setRequestMethod(type.name()); c.setUseCaches(false); c.setDefaultUseCaches(false); c.setConnectTimeout(5000); c.setReadTimeout(5000); c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.52 Safari/537.36 PhantomBotJ/2015"); c.setRequestProperty("Content-Type", "application/json-rpc"); c.setRequestProperty("Content-length", "0"); if (!post.isEmpty()) { c.setDoOutput(true); } preconnect = new Date(); c.connect(); postconnect = new Date(); if (!post.isEmpty()) { try (BufferedOutputStream o = new BufferedOutputStream(c.getOutputStream())) { IOUtils.write(post, o); } } String content; cl = c.getContentLengthLong(); responsecode = c.getResponseCode(); if (c.getResponseCode() == 200) { i = new BufferedInputStream(c.getInputStream()); } else { i = new BufferedInputStream(c.getErrorStream()); } /* * if (i != null) { available = i.available(); * * while (available == 0 && (new Date().getTime() - * postconnect.getTime()) < 450) { Thread.sleep(500); available = * i.available(); } * * if (available == 0) { i = new * BufferedInputStream(c.getErrorStream()); * * if (i != null) { available = i.available(); } } } * * if (available == 0) { content = "{}"; } else { content = * IOUtils.toString(i, c.getContentEncoding()); } */ content = IOUtils.toString(i, c.getContentEncoding()); rawcontent = content; prejson = new Date(); j = new JSONObject(content); j.put("_success", true); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", c.getResponseCode()); j.put("_available", available); j.put("_exception", ""); j.put("_exceptionMessage", ""); j.put("_content", content); postjson = new Date(); } catch (JSONException ex) { if (ex.getMessage().contains("A JSONObject text must begin with")) { j = new JSONObject("{}"); j.put("_success", true); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "MalformedJSONData (HTTP " + responsecode + ")"); j.put("_exceptionMessage", ""); j.put("_content", rawcontent); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (NullPointerException ex) { com.gmt2001.Console.err.printStackTrace(ex); } catch (MalformedURLException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "MalformedURLException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (PhantomBot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (SocketTimeoutException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "SocketTimeoutException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (PhantomBot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (IOException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "IOException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (PhantomBot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } catch (Exception ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "Exception [" + ex.getClass().getName() + "]"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (PhantomBot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } if (i != null) { try { i.close(); } catch (IOException ex) { j.put("_success", false); j.put("_type", type.name()); j.put("_url", url); j.put("_post", post); j.put("_http", 0); j.put("_available", available); j.put("_exception", "IOException"); j.put("_exceptionMessage", ex.getMessage()); j.put("_content", ""); if (PhantomBot.enableDebugging) { com.gmt2001.Console.err.printStackTrace(ex); } else { com.gmt2001.Console.err.logStackTrace(ex); } } } if (PhantomBot.enableDebugging) { com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetData Timers " + (preconnect.getTime() - start.getTime()) + " " + (postconnect.getTime() - start.getTime()) + " " + (prejson.getTime() - start.getTime()) + " " + (postjson.getTime() - start.getTime()) + " " + start.toString() + " " + postjson.toString()); com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetData Exception " + j.getString("_exception") + " " + j.getString("_exceptionMessage")); com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetData HTTP/Available " + j.getInt("_http") + "(" + responsecode + ")/" + j.getInt("_available") + "(" + cl + ")"); com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetData RawContent[0,100] " + j.getString("_content").substring(0, Math.min(100, j.getString("_content").length()))); } return j; }