List of usage examples for java.io ByteArrayInputStream close
public void close() throws IOException
From source file:org.apache.synapse.message.store.impl.rabbitmq.RabbitMQConsumer.java
public MessageContext receive() { if (!checkConnection()) { if (!reconnect()) { if (logger.isDebugEnabled()) { logger.debug(getId() + " cannot receive message from store. Can not reconnect."); }//w ww . j a v a 2 s .c o m return null; } else { logger.info(getId() + " reconnected to store."); isReceiveError = false; } } //setting channel if (channel != null) { if (!channel.isOpen()) { if (!setChannel()) { logger.info(getId() + " unable to create the channel."); return null; } } } else { if (!setChannel()) { logger.info(getId() + " unable to create the channel."); return null; } } //receive messages try { GetResponse delivery = null; delivery = channel.basicGet(queueName, false); if (delivery != null) { //deserilizing message StorableMessage storableMessage = null; ByteArrayInputStream bis = new ByteArrayInputStream(delivery.getBody()); ObjectInput in = new ObjectInputStream(bis); try { storableMessage = (StorableMessage) in.readObject(); } catch (ClassNotFoundException e) { logger.error(getId() + "unable to read the stored message" + e); channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); } bis.close(); in.close(); org.apache.axis2.context.MessageContext axis2Mc = store.newAxis2Mc(); MessageContext synapseMc = store.newSynapseMc(axis2Mc); synapseMc = MessageConverter.toMessageContext(storableMessage, axis2Mc, synapseMc); updateCache(delivery, synapseMc, null, false); if (logger.isDebugEnabled()) { logger.debug(getId() + " Received MessageId:" + delivery.getProps().getMessageId()); } return synapseMc; } } catch (ShutdownSignalException sse) { logger.error(getId() + " connection error when receiving messages" + sse); } catch (IOException ioe) { logger.error(getId() + " connection error when receiving messages" + ioe); } return null; }
From source file:com.activecq.experiments.redis.impl.RedisSessionUtilImpl.java
protected Object deserialize(final byte[] bytes) throws IOException, ClassNotFoundException { if (bytes == null) { return null; }// w ww . j a v a2 s. co m ByteArrayInputStream in = new ByteArrayInputStream(bytes); ObjectInputStream is = new ObjectInputStream(in); try { return is.readObject(); } finally { in.close(); is.close(); } }
From source file:org.hupo.psi.mi.psicquic.ws.IndexBasedPsicquicRestService.java
private Response.ResponseBuilder prepareResponse(Response.ResponseBuilder responseBuilder, Object entity, long totalCount, boolean compressed) throws IOException { if (compressed) { if (entity instanceof InputStream) { CompressedStreamingOutput streamingOutput = new CompressedStreamingOutput((InputStream) entity); responseBuilder.entity(new GenericEntity<CompressedStreamingOutput>(streamingOutput) { });// w ww . j a va 2 s. c o m } else if (entity instanceof String) { ByteArrayInputStream inputStream = new ByteArrayInputStream(((String) entity).getBytes()); try { CompressedStreamingOutput streamingOutput = new CompressedStreamingOutput(inputStream); responseBuilder.entity(new GenericEntity<CompressedStreamingOutput>(streamingOutput) { }); } finally { inputStream.close(); } } else if (entity instanceof EntrySet) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PsimiXmlWriter254 xmlWriter254 = new PsimiXmlWriter254(); try { xmlWriter254.marshall((EntrySet) entity, baos); ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); try { CompressedStreamingOutput streamingOutput = new CompressedStreamingOutput(inputStream); responseBuilder.entity(new GenericEntity<CompressedStreamingOutput>(streamingOutput) { }); } finally { inputStream.close(); } } catch (Throwable e) { throw new IOException("Problem marshalling XML", e); } finally { baos.close(); } } else { responseBuilder.entity(new GenericEntity<Object>(entity) { }); } responseBuilder.header("Content-Encoding", "gzip"); } else { responseBuilder.entity(new GenericEntity<Object>(entity) { }); } prepareHeaders(responseBuilder).header("X-PSICQUIC-Count", String.valueOf(totalCount)); return responseBuilder; }
From source file:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private int fetchIntInternal(AbstractMemberMetaData mmd, byte[] bytes) { int value;/*from w w w .j a v a2 s.co m*/ if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null) { return Integer.valueOf(dflt).intValue(); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readInt(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { value = Bytes.toInt(bytes); } return value; }
From source file:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private long fetchLongInternal(AbstractMemberMetaData mmd, byte[] bytes) { long value;/*w w w .j a va 2 s. c o m*/ if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null) { return Long.valueOf(dflt).longValue(); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readLong(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { value = Bytes.toLong(bytes); } return value; }
From source file:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private char fetchCharInternal(AbstractMemberMetaData mmd, byte[] bytes) { char value;/*from w w w. j a v a 2 s. c om*/ if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null && dflt.length() > 0) { return dflt.charAt(0); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readChar(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { String strValue = new String(bytes, Charsets.UTF_8); value = strValue.charAt(0); } return value; }
From source file:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private float fetchFloatInternal(AbstractMemberMetaData mmd, byte[] bytes) { float value;/*from w ww . ja v a 2 s . c om*/ if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null) { return Float.valueOf(dflt).floatValue(); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readFloat(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { value = Bytes.toFloat(bytes); } return value; }
From source file:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private short fetchShortInternal(AbstractMemberMetaData mmd, byte[] bytes) { short value;//from w w w . ja v a 2 s . c o m if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null) { return Short.valueOf(dflt).shortValue(); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readShort(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { value = Bytes.toShort(bytes); } return value; }
From source file:com.inmobi.grill.driver.hive.TestRemoteHiveDriver.java
private QueryContext readContext(byte[] bytes, GrillDriver driver) throws IOException, ClassNotFoundException { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream in = new ObjectInputStream(bais); QueryContext ctx;//w ww. ja v a 2 s. co m try { ctx = (QueryContext) in.readObject(); boolean driverAvailable = in.readBoolean(); if (driverAvailable) { String clsName = in.readUTF(); ctx.setSelectedDriver(driver); } } finally { in.close(); bais.close(); } return ctx; }