/** * Writes this instance to the given raw data object. * * @param out {@code non-null;} where to write to */ public final void writeTo(AnnotatedOutput out) { throwIfNotPrepared(); align(out); int cursor = out.getCursor(); if (fileOffset < 0) { fileOffset = cursor; } else if (fileOffset != cursor) { throw new RuntimeException("alignment mismatch: for " + this + ", at " + cursor + ", but expected " + fileOffset); } if (out.annotates()) { if (name != null) { out.annotate(0, "\n" + name + ":"); } else if (cursor != 0) { out.annotate(0, "\n"); } } writeTo0(out); }
/** * Gets the absolute item offset. The offset is from the start of * the file which the instance was written to. * * @return {@code >= 0;} the offset * @throws RuntimeException thrown if the offset is not yet known */ public final int getAbsoluteOffset() { if (offset < 0) { throw new RuntimeException("offset not yet known"); } return addedTo.getAbsoluteOffset(offset); }
/** * Adds the given list of items to the statistics. * * @param list {@code non-null;} the list of items to add */ public void addAll(Section list) { Collection<? extends Item> items = list.items(); for (Item item : items) { add(item); } }
/** * Prepares this instance for writing. This performs any necessary * prerequisites, including particularly adding stuff to other * sections. This method may only be called once per instance; * subsequent calls will throw an exception. */ public final void prepare() { throwIfPrepared(); prepare0(); prepared = true; }
if ((one == callSiteIds || one == methodHandles) && one.items().isEmpty()) { int placedAt = one.setFileOffset(offset); if (placedAt < offset) { throw new RuntimeException("bogus placement for section " + i); offset = placedAt + one.writeSize(); } catch (RuntimeException ex) { throw ExceptionWithContext.withContext(ex, try { final Section one = sections[i]; if ((one == callSiteIds || one == methodHandles) && one.items().isEmpty()) { continue; final int zeroCount = one.getFileOffset() - out.getCursor(); if (zeroCount < 0) { throw new ExceptionWithContext("excess write of " + one.writeTo(out); } catch (RuntimeException ex) { ExceptionWithContext ec;
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { // Encode the data and note the size. try { encoded = encode(addedTo.getFile(), null, null, null, false); setWriteSize(encoded.length); } catch (RuntimeException ex) { throw ExceptionWithContext.withContext(ex, "...while placing debug info for " + ref.toHuman()); } }
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int value = type.getMapValue(); int offset; if (firstItem == null) { offset = section.getFileOffset(); } else { offset = section.getAbsoluteItemOffset(firstItem); } if (out.annotates()) { out.annotate(0, offsetString() + ' ' + type.getTypeName() + " map"); out.annotate(2, " type: " + Hex.u2(value) + " // " + type.toString()); out.annotate(2, " unused: 0"); out.annotate(4, " size: " + Hex.u4(itemCount)); out.annotate(4, " offset: " + Hex.u4(offset)); } out.writeShort(value); out.writeShort(0); // unused out.writeInt(itemCount); out.writeInt(offset); } }
Section firstDataSection = file.getFirstDataSection(); Section lastDataSection = file.getLastDataSection(); int dataOff = firstDataSection.getFileOffset(); int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff;
int placedAt = one.setFileOffset(offset); if (placedAt < offset) { throw new RuntimeException("bogus placement for section " + i); offset = placedAt + one.writeSize(); } catch (RuntimeException ex) { throw ExceptionWithContext.withContext(ex, try { Section one = sections[i]; int zeroCount = one.getFileOffset() - out.getCursor(); if (zeroCount < 0) { throw new ExceptionWithContext("excess write of " + (-zeroCount)); out.writeZeroes(one.getFileOffset() - out.getCursor()); one.writeTo(out); } catch (RuntimeException ex) { ExceptionWithContext ec;
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { // Encode the data and note the size. ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); encodeOutput(addedTo.getFile(), out); encodedForm = out.toByteArray(); setWriteSize(encodedForm.length); }
/** * Prepares this instance for writing. This performs any necessary * prerequisites, including particularly adding stuff to other * sections. This method may only be called once per instance; * subsequent calls will throw an exception. */ public final void prepare() { throwIfPrepared(); prepare0(); prepared = true; }
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int value = type.getMapValue(); int offset; if (firstItem == null) { offset = section.getFileOffset(); } else { offset = section.getAbsoluteItemOffset(firstItem); } if (out.annotates()) { out.annotate(0, offsetString() + ' ' + type.getTypeName() + " map"); out.annotate(2, " type: " + Hex.u2(value) + " // " + type.toString()); out.annotate(2, " unused: 0"); out.annotate(4, " size: " + Hex.u4(itemCount)); out.annotate(4, " offset: " + Hex.u4(offset)); } out.writeShort(value); out.writeShort(0); // unused out.writeInt(itemCount); out.writeInt(offset); } }
Section firstDataSection = file.getFirstDataSection(); Section lastDataSection = file.getLastDataSection(); int dataOff = firstDataSection.getFileOffset(); int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff;
int placedAt = one.setFileOffset(offset); if (placedAt < offset) { throw new RuntimeException("bogus placement for section " + i); offset = placedAt + one.writeSize(); } catch (RuntimeException ex) { throw ExceptionWithContext.withContext(ex, try { Section one = sections[i]; int zeroCount = one.getFileOffset() - out.getCursor(); if (zeroCount < 0) { throw new ExceptionWithContext("excess write of " + (-zeroCount)); out.writeZeroes(one.getFileOffset() - out.getCursor()); one.writeTo(out); } catch (RuntimeException ex) { ExceptionWithContext ec;
/** * Writes this instance to the given raw data object. * * @param out {@code non-null;} where to write to */ public final void writeTo(AnnotatedOutput out) { throwIfNotPrepared(); align(out); int cursor = out.getCursor(); if (fileOffset < 0) { fileOffset = cursor; } else if (fileOffset != cursor) { throw new RuntimeException("alignment mismatch: for " + this + ", at " + cursor + ", but expected " + fileOffset); } if (out.annotates()) { if (name != null) { out.annotate(0, "\n" + name + ":"); } else if (cursor != 0) { out.annotate(0, "\n"); } } writeTo0(out); }
/** {@inheritDoc} */ @Override protected void place0(Section addedTo, int offset) { // Encode the data and note the size. ByteArrayAnnotatedOutput out = new ByteArrayAnnotatedOutput(); encodeOutput(addedTo.getFile(), out); encodedForm = out.toByteArray(); setWriteSize(encodedForm.length); }
/** * Prepares this instance for writing. This performs any necessary * prerequisites, including particularly adding stuff to other * sections. This method may only be called once per instance; * subsequent calls will throw an exception. */ public final void prepare() { throwIfPrepared(); prepare0(); prepared = true; }
/** {@inheritDoc} */ @Override protected void writeTo0(DexFile file, AnnotatedOutput out) { int value = type.getMapValue(); int offset; if (firstItem == null) { offset = section.getFileOffset(); } else { offset = section.getAbsoluteItemOffset(firstItem); } if (out.annotates()) { out.annotate(0, offsetString() + ' ' + type.getTypeName() + " map"); out.annotate(2, " type: " + Hex.u2(value) + " // " + type.toString()); out.annotate(2, " unused: 0"); out.annotate(4, " size: " + Hex.u4(itemCount)); out.annotate(4, " offset: " + Hex.u4(offset)); } out.writeShort(value); out.writeShort(0); // unused out.writeInt(itemCount); out.writeInt(offset); } }
Section firstDataSection = file.getFirstDataSection(); Section lastDataSection = file.getLastDataSection(); int dataOff = firstDataSection.getFileOffset(); int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff;
/** * Adds the given list of items to the statistics. * * @param list {@code non-null;} the list of items to add */ public void addAll(Section list) { Collection<? extends Item> items = list.items(); for (Item item : items) { add(item); } }