private Object objectFromInputStreamInReentrantMode(InputStream is) throws IOException, ClassNotFoundException, InterruptedException { int len = is.available(); Object o = null; if (len != 0) { ExposedByteArrayOutputStream bytes = new ExposedByteArrayOutputStream(len); byte[] buf = new byte[Math.min(len, 1024)]; int bytesRead; while ((bytesRead = is.read(buf, 0, buf.length)) != -1) { bytes.write(buf, 0, bytesRead); } is = new ByteArrayInputStream(bytes.getRawBuffer(), 0, bytes.size()); ObjectInput unmarshaller = marshaller.startObjectInput(is, false); try { o = marshaller.objectFromObjectStream(unmarshaller); } finally { marshaller.finishObjectInput(unmarshaller); } } return o; }
/** * Reads from a stream the number of entries (long) then the entries themselves. */ @Override public void fromStream(ObjectInput in) throws CacheLoaderException { try { log.debug("fromStream()"); int count = 0; while (true) { count++; InternalCacheEntry entry = (InternalCacheEntry) getMarshaller().objectFromObjectStream(in); if (entry == null) break; store(entry); } log.debugf("read %d entries", count); } catch (IOException e) { throw new CacheLoaderException(e); } catch (ClassNotFoundException e) { throw new CacheLoaderException(e); } catch (InterruptedException ie) { if (log.isTraceEnabled()) log.trace("Interrupted while reading from stream"); Thread.currentThread().interrupt(); } }