use of org.fusesource.hawtbuf.ByteArrayInputStream in project spring-boot by spring-projects.
the class HeapdumpMvcEndpointTests method invokeShouldReturnGzipContent.
@Test
public void invokeShouldReturnGzipContent() throws Exception {
MvcResult result = this.mvc.perform(get("/heapdump")).andExpect(status().isOk()).andReturn();
byte[] bytes = result.getResponse().getContentAsByteArray();
GZIPInputStream stream = new GZIPInputStream(new ByteArrayInputStream(bytes));
byte[] uncompressed = FileCopyUtils.copyToByteArray(stream);
assertThat(uncompressed).isEqualTo("HEAPDUMP".getBytes());
}
use of org.fusesource.hawtbuf.ByteArrayInputStream in project vcell by virtualcell.
the class VCMessageJms method loadBlobFile.
/**
* see Property jmsBlobMessageMinSize "vcell.jms.blobMessageMinSize"
* see Property jmsBlobMessageTempDir "vcell.jms.blobMessageTempDir"
* see class MessageProducerSessionJms
*
* 1) Message Producer serializes into byte[] and compares size with PropertyLoader.jmsBlobMessageMinSize.
* 2) For Large Object Messages (> threshold bytes), MessageProducerSessionJms writes bytes to a local file (e.g. MyBlobMessageTempDir/BlobMessage2295645974283237270.data).
* 3) Pass file name as message properties so that receiver can delete file when done.
* 4) consumer-side VCMessage infrastructure receives BlobMessage and invokes VCMessageJms.loadBlobMessage()
* 5) loadBlobMessage() reads object from stream and attempts to delete both original and broker files.
* 6) consumer's message listener calls getObjectContent() not knowing if it was sent as a Blob or not.
* 7) message consumer calls VCMessageJms.removeBlobFile() to clean up disk.
*/
public void loadBlobFile() {
if (blobObject != null) {
return;
}
if (jmsMessage instanceof ObjectMessage && propertyExists(BLOB_MESSAGE_PERSISTENCE_TYPE) && getStringProperty(BLOB_MESSAGE_PERSISTENCE_TYPE).equals(BLOB_MESSAGE_PERSISTENCE_TYPE_FILE)) {
try {
long t1 = System.currentTimeMillis();
//
// read serialized object from inputStream (from Broker's data file)
//
String blobFileName = jmsMessage.getStringProperty(BLOB_MESSAGE_FILE_NAME);
//
// get directory to retrieve Message BLOBs
//
File localBlobDir = new File(PropertyLoader.getRequiredProperty(PropertyLoader.jmsBlobMessageTempDir));
File producerBlobDir = new File(getStringProperty(BLOB_MESSAGE_PRODUCER_TEMPDIR));
blobFile = new File(localBlobDir, blobFileName);
if (!blobFile.exists()) {
blobFile = new File(producerBlobDir, blobFileName);
if (!blobFile.exists()) {
throw new RuntimeException("Message BLOB file \"" + blobFileName + "\" not found local=\"" + localBlobDir + "\" or producer=\"" + producerBlobDir + "\"");
}
}
FileInputStream fis = new FileInputStream(blobFile);
BufferedInputStream bis = new BufferedInputStream(fis);
ObjectInputStream ois = new ObjectInputStream(bis);
blobObject = (Serializable) ois.readObject();
ois.close();
bis.close();
fis.close();
delegate.onTraceEvent("VCMessageJms.loadBlobFile(): size=" + jmsMessage.getIntProperty(BLOB_MESSAGE_OBJECT_SIZE) + ", type=" + jmsMessage.getStringProperty(BLOB_MESSAGE_OBJECT_TYPE) + ", elapsedTime = " + (System.currentTimeMillis() - t1) + " ms");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
if (jmsMessage instanceof ObjectMessage && propertyExists(BLOB_MESSAGE_PERSISTENCE_TYPE) && getStringProperty(BLOB_MESSAGE_PERSISTENCE_TYPE).equals(BLOB_MESSAGE_PERSISTENCE_TYPE_MONGODB)) {
try {
long t1 = System.currentTimeMillis();
//
// read serialized object from inputStream (from Broker's data file)
//
String mongo_objectid_hex = jmsMessage.getStringProperty(BLOB_MESSAGE_MONGODB_OBJECTID);
blobObjectId = new ObjectId(mongo_objectid_hex);
byte[] blob = VCMongoDbDriver.getInstance().getBLOB(blobObjectId);
ByteArrayInputStream bis = new ByteArrayInputStream(blob);
ObjectInputStream ois = new ObjectInputStream(bis);
blobObject = (Serializable) ois.readObject();
ois.close();
bis.close();
delegate.onTraceEvent("VCMessageJms.loadBlobFile(): size=" + jmsMessage.getIntProperty(BLOB_MESSAGE_OBJECT_SIZE) + ", type=" + jmsMessage.getStringProperty(BLOB_MESSAGE_OBJECT_TYPE) + ", elapsedTime = " + (System.currentTimeMillis() - t1) + " ms");
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
}
Aggregations