/** * Check if a record is fresh. * * @param record the record to check * @return true if the record is fresh */ private boolean isFresh(Record record) { double period = record.data.getMetaInfo().getFreshnessPeriod(); return period < 0 || record.addedAt + (long) period > System.currentTimeMillis(); }
public InMemoryContentStore(int freshnessMs) { this.template = new Data(); this.template.getMetaInfo().setFreshnessPeriod(freshnessMs); this.store = DefaultNameTree.newRootTree(); }
private boolean hasFinalBlockId(Data data) { return data.getMetaInfo().getFinalBlockId().getValue().size() > 0; }
private static void sendAttributes(Face face, Name publisherName) { Data data = new Data(publisherName); data.setContent(new Blob("[attributes here]")); data.getMetaInfo().setFreshnessPeriod(ATTRIBUTES_FRESHNESS_PERIOD); try { face.putData(data); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to publish attributes for publisher: " + publisherName, e); } }
/** * Segment a stream of bytes into a list of Data packets; this must read all the bytes first in order to determine the * end segment for FinalBlockId. TODO this could be smarter and only add segments if necessary * * @param template the {@link Data} packet to use for the segment {@link Name}, {@link net.named_data.jndn.MetaInfo}, * etc. * @param bytes an {@link InputStream} to the bytes to segment * @return a list of segmented {@link Data} packets * @throws IOException if the stream fails */ public static List<Data> segment(Data template, InputStream bytes, int segmentSize) throws IOException { List<Data> segments = new ArrayList<>(); byte[] readBytes = readAll(bytes); int numBytes = readBytes.length; int numPackets = (int) Math.ceil((double) numBytes / segmentSize); ByteBuffer buffer = ByteBuffer.wrap(readBytes, 0, numBytes); Name.Component lastSegment = Name.Component.fromNumberWithMarker((long) numPackets - 1, NDN_SEGMENT_MARKER); for (int i = 0; i < numPackets; i++) { Data segment = new Data(template); segment.getName().appendSegment(i); segment.getMetaInfo().setFinalBlockId(lastSegment); byte[] content = new byte[Math.min(segmentSize, buffer.remaining())]; buffer.get(content); segment.setContent(new Blob(content)); segments.add(segment); } return segments; }
end = data.getMetaInfo().getFinalBlockId().toNumberWithMarker(PARTITION_MARKER); } catch (EncodingException ex) { onException(ex);
finalBlockId = data.getMetaInfo().getFinalBlockId().toSegment(); } catch (EncodingException e) { throw new IOException("Requested segmented stream is unbounded", e);