public ByteBuffer map(long startPosition, long size) throws IOException { if (startPosition < 0 || size < 0) { throw new IOException("startPosition and size must both be >= 0"); } //make sure that start+size aren't greater than avail size //in raf. BigInteger end = BigInteger.valueOf(startPosition); end = end.add(BigInteger.valueOf(size)); if (end.compareTo(BigInteger.valueOf(raf.length())) > 0) { throw new IOException("requesting read past end of stream"); } raf.seek(startPosition); int payLoadSize = l2i(size); //hack to check for potential overflow if (Long.MAX_VALUE-payLoadSize < startPosition || Long.MAX_VALUE-payLoadSize > raf.length()) { throw new IOException("requesting read past end of stream"); } byte[] payload = new byte[payLoadSize]; raf.readFully(payload); return ByteBuffer.wrap(payload); }
public ByteBuffer map(long startPosition, long size) throws IOException { raf.seek(startPosition); byte[] payload = new byte[l2i(size)]; raf.readFully(payload); return ByteBuffer.wrap(payload); }
public synchronized ByteBuffer map(long startPosition, long size) throws IOException { ByteBuffer bb = ByteBuffer.allocate(l2i(size)); fc.read(bb, startPosition); return (ByteBuffer) bb.rewind(); }
public ByteBuffer asByteBuffer() { ensureData(); byte[] bCopy = new byte[l2i(size)]; ByteBuffer copy = ByteBuffer.wrap(bCopy); for (ByteBuffer b : data) { copy.put(b.duplicate()); } copy.rewind(); return copy; }
public void addAndReplace(Box box) { data.position(l2i(box.getSize())); data = data.slice(); replacers.add(box); }
public void parse(ReadableByteChannel readableByteChannel, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { this.header = header; this.contentSize = contentSize; if (readableByteChannel instanceof FileChannel && (contentSize > AbstractBox.MEM_MAP_THRESHOLD)) { this.fileChannel = ((FileChannel) readableByteChannel); this.startPosition = ((FileChannel) readableByteChannel).position(); ((FileChannel) readableByteChannel).position(((FileChannel) readableByteChannel).position() + contentSize); } else { content = ChannelHelper.readFully(readableByteChannel, l2i(contentSize)); cache.put(0l, new SoftReference<ByteBuffer>(content)); } }
public ByteBuffer map(long startPosition, long size) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(l2i(size)); transferTo(startPosition, size, Channels.newChannel(baos)); return ByteBuffer.wrap(baos.toByteArray()); }
public void addAndReplace(Box box) { data.position(l2i(box.getSize())); data = data.slice(); replacers.add(box); }
@Override public void parse(DataSource dataSource, ByteBuffer header, long contentSize, BoxParser boxParser) throws IOException { ByteBuffer byteBuffer = ByteBuffer.allocate(l2i(contentSize)); dataSource.read(byteBuffer); byteBuffer.position(6); dataReferenceIndex = IsoTypeReader.readUInt16(byteBuffer); vc1Content = new byte[byteBuffer.remaining()]; byteBuffer.get(vc1Content); }
private int getTrafSize(TrackFragmentBox traf) { List<Box> boxes = traf.getBoxes(); int size = 0; for (int i = 0; i < boxes.size(); i++) { Box b = boxes.get(i); if (b instanceof TrackRunBox) { size += l2i(((TrackRunBox) b).getSampleCount()); } } return size; }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int numberOfEntries = l2i(IsoTypeReader.readUInt32(content)); entries = new ArrayList<Entry>(numberOfEntries); for (int i = 0; i < numberOfEntries; i++) { Entry e = new Entry(l2i(IsoTypeReader.readUInt32(content)), content.getInt()); entries.add(e); } }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int numberOfEntries = l2i(IsoTypeReader.readUInt32(content)); entries = new ArrayList<Entry>(numberOfEntries); for (int i = 0; i < numberOfEntries; i++) { Entry e = new Entry(l2i(IsoTypeReader.readUInt32(content)), content.getInt()); entries.add(e); } }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int numberOfEntries = l2i(IsoTypeReader.readUInt32(content)); entries = new ArrayList<Entry>(numberOfEntries); for (int i = 0; i < numberOfEntries; i++) { Entry e = new Entry(l2i(IsoTypeReader.readUInt32(content)), content.getInt()); entries.add(e); } }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int entryCount = l2i(IsoTypeReader.readUInt32(content)); entries = new LinkedList<Entry>(); for (int i = 0; i < entryCount; i++) { entries.add(new Entry(this, content)); } }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int entryCount = l2i(IsoTypeReader.readUInt32(content)); entries = new LinkedList<Entry>(); for (int i = 0; i < entryCount; i++) { entries.add(new Entry(this, content)); } }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int entryCount = l2i(IsoTypeReader.readUInt32(content)); entries = new LinkedList<Entry>(); for (int i = 0; i < entryCount; i++) { entries.add(new Entry(this, content)); } }
public int read(ByteBuffer byteBuffer) throws IOException { if (endPosition == dataSource.position()) { return -1; } else if (byteBuffer.remaining() > endPosition - dataSource.position()) { ByteBuffer bb = ByteBuffer.allocate(l2i(endPosition - dataSource.position())); dataSource.read(bb); byteBuffer.put((ByteBuffer) bb.rewind()); return bb.capacity(); } else { return dataSource.read(byteBuffer); } }
public void getContent(ByteBuffer bb) { if (editListBox.getVersion() == 1) { IsoTypeWriter.writeUInt64(bb, segmentDuration); IsoTypeWriter.writeUInt64(bb, mediaTime); } else { IsoTypeWriter.writeUInt32(bb, l2i(segmentDuration)); bb.putInt(l2i(mediaTime)); } IsoTypeWriter.writeFixedPoint1616(bb, mediaRate); }