List of usage examples for com.google.common.io ByteSource empty
public static ByteSource empty()
From source file:org.jclouds.openstack.swift.v1.blobstore.functions.ToSwiftObject.java
private static Payload payload(long bytes, String contentType) { Payload payload = Payloads.newByteSourcePayload(ByteSource.empty()); payload.getContentMetadata().setContentLength(bytes); payload.getContentMetadata().setContentType(contentType); return payload; }
From source file:ratpack.configuration.internal.DefaultConfigurationSource.java
public DefaultConfigurationSource(ClassLoader classLoader, Properties overrideProperties, Properties defaultProperties) { this(classLoader, ByteSource.empty(), overrideProperties, defaultProperties); }
From source file:com.dyn.client.v3.traffic.handlers.GetJobRedirectionRetryHandler.java
@Inject protected GetJobRedirectionRetryHandler(BackoffLimitedRetryHandler backoffHandler) { super(backoffHandler); this.emptyPayload = Payloads.newByteSourcePayload(ByteSource.empty()); this.emptyPayload.getContentMetadata().setContentType(APPLICATION_JSON); }
From source file:org.jclouds.blobstore.strategy.internal.MarkerFileMkdirStrategy.java
public void execute(String containerName, String directory) { blobStore.putBlob(containerName,//w w w.java 2 s . co m blobStore.blobBuilder(directory + directorySuffix).type(StorageType.RELATIVE_PATH) .payload(ByteSource.empty()).contentLength(0L).contentType("application/directory") .build()); }
From source file:com.example.app.model.UserProfileDAO.java
/** * Save UserProfile.//from w ww. j av a 2 s . c o m * * @param userProfile the user profile to save. */ public void saveUserProfile(UserProfile userProfile) { beginTransaction(); boolean success = false; try { final long id = userProfile.getId(); String name = userProfile.getName().getLast() + ", " + userProfile.getName().getFirst(); String pictureName = name + " #" + id; final Session session = getSession(); FileEntity picture = userProfile.getPicture(); if (picture != null) { pictureName += getExtensionWithDot(picture); TemporaryFileEntity tfe = null; if (picture instanceof TemporaryFileEntity) tfe = (TemporaryFileEntity) picture; ByteSource fileData = tfe != null ? tfe.asByteSource() : ByteSource.empty(); // Ensure our picture file has a unique file name consistent with the profile. if (picture.getId() < 1) { final CmsSite site = userProfile.getSite(); final DirectoryEntity rootDirectory = FileSystemDirectory.getRootDirectory(site); DirectoryEntity parentDirectory = _fileSystemDAO.mkdirs(rootDirectory, null, "UserProfilePictures"); picture.setName(pictureName); picture = _fileSystemDAO.store(new StoreRequest(parentDirectory, picture, fileData) .withCreateMode(overwrite).withRequest(Event.getRequest())); userProfile.setPicture(picture); } else { EntityRetriever er = EntityRetriever.getInstance(); picture = er.reattachIfNecessary(tfe != null ? tfe.getFileEntity() : picture); picture.setName(pictureName); _fileSystemDAO.store(new StoreRequest(picture, fileData).withCreateMode(overwrite) .withRequest(Event.getRequest())); userProfile.setPicture(picture); // In case we are cascading. if (tfe != null) tfe.deleteStream(); } } if (isTransient(userProfile) || isAttached(userProfile)) session.saveOrUpdate(userProfile); else session.merge(userProfile); if (picture != null && id == 0) { // New user profile. Update picture name to include the ID pictureName = name + " #" + userProfile.getId() + getExtensionWithDot(picture); picture.setName(pictureName); _fileSystemDAO.store(new StoreRequest(picture)); } success = true; } catch (HibernateException ioe) { throw new RuntimeException("Unable to access filesystem.", ioe); } finally { if (success) commitTransaction(); else recoverableRollbackTransaction(); } }
From source file:com.example.app.model.DemoUserProfileDAO.java
/** * Save UserProfile./*from ww w .j av a2 s . c om*/ * * @param demoUserProfile the user profile to save. */ public void saveUserProfile(DemoUserProfile demoUserProfile) { beginTransaction(); boolean success = false; try { final long id = demoUserProfile.getId(); String name = demoUserProfile.getName().getLast() + ", " + demoUserProfile.getName().getFirst(); String pictureName = name + " #" + id; final Session session = getSession(); FileEntity picture = demoUserProfile.getPicture(); if (picture != null) { pictureName += getExtensionWithDot(picture); TemporaryFileEntity tfe = null; if (picture instanceof TemporaryFileEntity) tfe = (TemporaryFileEntity) picture; ByteSource fileData = tfe != null ? tfe.asByteSource() : ByteSource.empty(); // Ensure our picture file has a unique file name consistent with the profile. if (picture.getId() < 1) { final CmsSite site = demoUserProfile.getSite(); final DirectoryEntity rootDirectory = FileSystemDirectory.getRootDirectory(site); DirectoryEntity parentDirectory = _fileSystemDAO.mkdirs(rootDirectory, null, "UserProfilePictures"); picture.setName(pictureName); picture = _fileSystemDAO.store(new StoreRequest(parentDirectory, picture, fileData) .withCreateMode(overwrite).withRequest(Event.getRequest())); demoUserProfile.setPicture(picture); } else { EntityRetriever er = EntityRetriever.getInstance(); picture = er.reattachIfNecessary(tfe != null ? tfe.getFileEntity() : picture); picture.setName(pictureName); _fileSystemDAO.store(new StoreRequest(picture, fileData).withCreateMode(overwrite) .withRequest(Event.getRequest())); demoUserProfile.setPicture(picture); // In case we are cascading. if (tfe != null) tfe.deleteStream(); } } if (isTransient(demoUserProfile) || isAttached(demoUserProfile)) session.saveOrUpdate(demoUserProfile); else session.merge(demoUserProfile); if (picture != null && id == 0) { // New user profile. Update picture name to include the ID pictureName = name + " #" + demoUserProfile.getId() + getExtensionWithDot(picture); picture.setName(pictureName); _fileSystemDAO.store(new StoreRequest(picture)); } success = true; } catch (HibernateException ioe) { throw new RuntimeException("Unable to access filesystem.", ioe); } finally { if (success) commitTransaction(); else recoverableRollbackTransaction(); } }
From source file:org.jclouds.openstack.swift.v1.functions.ParseObjectListFromResponse.java
private static Payload payload(long bytes, String hash, String contentType, Date expires) { Payload payload = Payloads.newByteSourcePayload(ByteSource.empty()); payload.getContentMetadata().setContentLength(bytes); payload.getContentMetadata().setContentType(contentType); payload.getContentMetadata().setExpires(expires); if (hash != null) { payload.getContentMetadata().setContentMD5(HashCode.fromBytes(base16().lowerCase().decode(hash))); }/* ww w .j a v a 2s. co m*/ return payload; }
From source file:com.metamx.http.client.response.SequenceInputStreamResponseHandler.java
@Override public ClientResponse<InputStream> done(ClientResponse<InputStream> clientResponse) { synchronized (done) { try {//from w w w . j ava 2 s .c om // An empty byte array is put at the end to give the SequenceInputStream.close() as something to close out // after done is set to true, regardless of the rest of the stream's state. queue.put(ByteSource.empty().openStream()); log.debug("Added terminal empty stream"); } catch (InterruptedException e) { log.warn(e, "Thread interrupted while adding to queue"); Thread.currentThread().interrupt(); throw Throwables.propagate(e); } catch (IOException e) { // This should never happen log.wtf(e, "The empty stream threw an IOException"); throw Throwables.propagate(e); } finally { log.debug("Done after adding %d bytes of streams", byteCount.get()); done.set(true); } } return ClientResponse.<InputStream>finished(clientResponse.getObj()); }
From source file:org.jclouds.glacier.util.AWSRequestSignerV4.java
private static HashCode buildHashedPayload(HttpRequest request) { HashingInputStream his = null;/*from ww w. ja v a2 s. c o m*/ try { his = new HashingInputStream(Hashing.sha256(), request.getPayload() == null ? ByteSource.empty().openStream() : request.getPayload().openStream()); ByteStreams.copy(his, ByteStreams.nullOutputStream()); return his.hash(); } catch (IOException e) { throw new HttpException("Error signing request", e); } finally { closeQuietly(his); } }
From source file:org.apache.druid.java.util.http.client.response.SequenceInputStreamResponseHandler.java
@Override public ClientResponse<InputStream> done(ClientResponse<InputStream> clientResponse) { synchronized (done) { try {/*from www. j a v a 2 s . c om*/ // An empty byte array is put at the end to give the SequenceInputStream.close() as something to close out // after done is set to true, regardless of the rest of the stream's state. queue.put(ByteSource.empty().openStream()); log.debug("Added terminal empty stream"); } catch (InterruptedException e) { log.warn(e, "Thread interrupted while adding to queue"); Thread.currentThread().interrupt(); throw Throwables.propagate(e); } catch (IOException e) { // This should never happen log.wtf(e, "The empty stream threw an IOException"); throw Throwables.propagate(e); } finally { log.debug("Done after adding %d bytes of streams", byteCount.get()); done.set(true); } } return ClientResponse.finished(clientResponse.getObj()); }