test_class.declarator: BIG = 2048L * 1024L * 1024L
test_class.modifier: private static final
test_class.original_string: private static final long BIG = 2048L * 1024L * 1024L;
test_class.type: long
test_class.var_name: BIG
test_class.declarator: DEFLATE_PARAMS = JreDeflateParameters.of(6, 0, true)
test_class.modifier: private static final
test_class.original_string: private static final JreDeflateParameters DEFLATE_PARAMS = JreDeflateParameters.of(6, 0, true);
test_class.type: JreDeflateParameters
test_class.var_name: DEFLATE_PARAMS
test_class.declarator: OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE =
        new TypedRange<Void>(BIG, 17L, null)
test_class.modifier: private static final
test_class.original_string: private static final TypedRange<Void> OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE =
        new TypedRange<Void>(BIG, 17L, null);
test_class.type: TypedRange<Void>
test_class.var_name: OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE
test_class.declarator: NEW_DELTA_FRIENDLY_UNCOMPRESS_RANGE =
        new TypedRange<JreDeflateParameters>(BIG - 100L, BIG, DEFLATE_PARAMS)
test_class.modifier: private static final
test_class.original_string: private static final TypedRange<JreDeflateParameters> NEW_DELTA_FRIENDLY_UNCOMPRESS_RANGE =
        new TypedRange<JreDeflateParameters>(BIG - 100L, BIG, DEFLATE_PARAMS);
test_class.type: TypedRange<JreDeflateParameters>
test_class.var_name: NEW_DELTA_FRIENDLY_UNCOMPRESS_RANGE
test_class.declarator: NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE =
        new TypedRange<JreDeflateParameters>(BIG, BIG, DEFLATE_PARAMS)
test_class.modifier: private static final
test_class.original_string: private static final TypedRange<JreDeflateParameters> NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE =
        new TypedRange<JreDeflateParameters>(BIG, BIG, DEFLATE_PARAMS);
test_class.type: TypedRange<JreDeflateParameters>
test_class.var_name: NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE
test_class.declarator: OLD_DELTA_FRIENDLY_UNCOMPRESS_PLAN =
        Collections.singletonList(OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE)
test_class.modifier: private static final
test_class.original_string: private static final List<TypedRange<Void>> OLD_DELTA_FRIENDLY_UNCOMPRESS_PLAN =
        Collections.singletonList(OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE);
test_class.type: List<TypedRange<Void>>
test_class.var_name: OLD_DELTA_FRIENDLY_UNCOMPRESS_PLAN
test_class.declarator: NEW_DELTA_FRIENDLY_UNCOMPRESS_PLAN =
        Collections.singletonList(NEW_DELTA_FRIENDLY_UNCOMPRESS_RANGE)
test_class.modifier: private static final
test_class.original_string: private static final List<TypedRange<JreDeflateParameters>> NEW_DELTA_FRIENDLY_UNCOMPRESS_PLAN =
        Collections.singletonList(NEW_DELTA_FRIENDLY_UNCOMPRESS_RANGE);
test_class.type: List<TypedRange<JreDeflateParameters>>
test_class.var_name: NEW_DELTA_FRIENDLY_UNCOMPRESS_PLAN
test_class.declarator: NEW_DELTA_FRIENDLY_RECOMPRESS_PLAN =
        Collections.singletonList(NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE)
test_class.modifier: private static final
test_class.original_string: private static final List<TypedRange<JreDeflateParameters>> NEW_DELTA_FRIENDLY_RECOMPRESS_PLAN =
        Collections.singletonList(NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE);
test_class.type: List<TypedRange<JreDeflateParameters>>
test_class.var_name: NEW_DELTA_FRIENDLY_RECOMPRESS_PLAN
test_class.declarator: DELTA_FRIENDLY_OLD_FILE_SIZE = BIG - 75L
test_class.modifier: private static final
test_class.original_string: private static final long DELTA_FRIENDLY_OLD_FILE_SIZE = BIG - 75L;
test_class.type: long
test_class.var_name: DELTA_FRIENDLY_OLD_FILE_SIZE
test_class.declarator: DELTA_FRIENDLY_NEW_FILE_SIZE = BIG + 75L
test_class.modifier: private static final
test_class.original_string: private static final long DELTA_FRIENDLY_NEW_FILE_SIZE = BIG + 75L;
test_class.type: long
test_class.var_name: DELTA_FRIENDLY_NEW_FILE_SIZE
test_class.declarator: PLAN =
        new PreDiffPlan(
            Collections.<QualifiedRecommendation>emptyList(),
            OLD_DELTA_FRIENDLY_UNCOMPRESS_PLAN,
            NEW_DELTA_FRIENDLY_UNCOMPRESS_PLAN,
            NEW_DELTA_FRIENDLY_RECOMPRESS_PLAN)
test_class.modifier: private static final
test_class.original_string: private static final PreDiffPlan PLAN =
        new PreDiffPlan(
            Collections.<QualifiedRecommendation>emptyList(),
            OLD_DELTA_FRIENDLY_UNCOMPRESS_PLAN,
            NEW_DELTA_FRIENDLY_UNCOMPRESS_PLAN,
            NEW_DELTA_FRIENDLY_RECOMPRESS_PLAN);
test_class.type: PreDiffPlan
test_class.var_name: PLAN
test_class.declarator: DELTA_CONTENT = "this is a really cool delta, woo"
test_class.modifier: private static final
test_class.original_string: private static final String DELTA_CONTENT = "this is a really cool delta, woo";
test_class.type: String
test_class.var_name: DELTA_CONTENT
test_class.declarator: deltaFile = null
test_class.modifier: private
test_class.original_string: private File deltaFile = null;
test_class.type: File
test_class.var_name: deltaFile
test_class.declarator: buffer = null
test_class.modifier: private
test_class.original_string: private ByteArrayOutputStream buffer = null;
test_class.type: ByteArrayOutputStream
test_class.var_name: buffer
test_class.file: feya/libraries/archive_diff/diff.generator/src/test/java/com/google/archivepatcher/generator/PatchWriterTest.java
test_class.identifier: PatchWriterTest
test_case.body: @Test
    public void testWriteV1Patch() throws IOException {
      // ---------------------------------------------------------------------------------------------
      // CAUTION - DO NOT CHANGE THIS FUNCTION WITHOUT DUE CONSIDERATION FOR BREAKING THE PATCH FORMAT
      // ---------------------------------------------------------------------------------------------
      // This test writes a simple patch with all the static data listed above and verifies it.
      // This code MUST be INDEPENDENT of the real patch parser code, even if it is partially
      // redundant; this guards against accidental changes to the patch writer that could alter the
      // format and otherwise escape detection.
      PatchWriter writer =
          new PatchWriter(
              PLAN, DELTA_FRIENDLY_OLD_FILE_SIZE, DELTA_FRIENDLY_NEW_FILE_SIZE, deltaFile);
      writer.writeV1Patch(buffer);
      DataInputStream patchIn = new DataInputStream(new ByteArrayInputStream(buffer.toByteArray()));
      byte[] eightBytes = new byte[8];
  
      // Start by reading the signature and flags
      patchIn.readFully(eightBytes);
      Assert.assertArrayEquals(PatchConstants.IDENTIFIER.getBytes("US-ASCII"), eightBytes);
      Assert.assertEquals(0, patchIn.readInt()); // Flags, all reserved in v1
  
      Assert.assertEquals(DELTA_FRIENDLY_OLD_FILE_SIZE, patchIn.readLong());
  
      // Read the uncompression instructions
      Assert.assertEquals(1, patchIn.readInt()); // Number of old archive uncompression instructions
      Assert.assertEquals(OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE.getOffset(), patchIn.readLong());
      Assert.assertEquals(OLD_DELTA_FRIENDLY_UNCOMPRESS_RANGE.getLength(), patchIn.readLong());
  
      // Read the recompression instructions
      Assert.assertEquals(1, patchIn.readInt()); // Number of new archive recompression instructions
      Assert.assertEquals(NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE.getOffset(), patchIn.readLong());
      Assert.assertEquals(NEW_DELTA_FRIENDLY_RECOMPRESS_RANGE.getLength(), patchIn.readLong());
      // Now the JreDeflateParameters for the record
      Assert.assertEquals(
          PatchConstants.CompatibilityWindowId.DEFAULT_DEFLATE.patchValue, patchIn.read());
      Assert.assertEquals(DEFLATE_PARAMS.level, patchIn.read());
      Assert.assertEquals(DEFLATE_PARAMS.strategy, patchIn.read());
      Assert.assertEquals(DEFLATE_PARAMS.nowrap ? 1 : 0, patchIn.read());
  
      // Delta section. V1 patches have exactly one delta entry and it is always mapped to the entire
      // file contents of the delta-friendly archives
      Assert.assertEquals(1, patchIn.readInt()); // Number of difference records
      Assert.assertEquals(PatchConstants.DeltaFormat.BSDIFF.patchValue, patchIn.read());
      Assert.assertEquals(0, patchIn.readLong()); // Old delta-friendly range start
      Assert.assertEquals(DELTA_FRIENDLY_OLD_FILE_SIZE, patchIn.readLong()); // old range length
      Assert.assertEquals(0, patchIn.readLong()); // New delta-friendly range start
      Assert.assertEquals(DELTA_FRIENDLY_NEW_FILE_SIZE, patchIn.readLong()); // new range length
      byte[] expectedDeltaContent = DELTA_CONTENT.getBytes("US-ASCII");
      Assert.assertEquals(expectedDeltaContent.length, patchIn.readLong());
      byte[] actualDeltaContent = new byte[expectedDeltaContent.length];
      patchIn.readFully(actualDeltaContent);
      Assert.assertArrayEquals(expectedDeltaContent, actualDeltaContent);
    }
test_case.class_method_signature: PatchWriterTest.testWriteV1Patch()
test_case.full_signature: @Test public void testWriteV1Patch()
test_case.identifier: testWriteV1Patch
test_case.invocations: writeV1Patch toByteArray readFully assertArrayEquals getBytes assertEquals readInt assertEquals readLong assertEquals readInt assertEquals getOffset readLong assertEquals getLength readLong assertEquals readInt assertEquals getOffset readLong assertEquals getLength readLong assertEquals read assertEquals read assertEquals read assertEquals read assertEquals readInt assertEquals read assertEquals readLong assertEquals readLong assertEquals readLong assertEquals readLong getBytes assertEquals readLong readFully assertArrayEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testWriteV1Patch()
focal_class.declarator: plan
focal_class.modifier: private final
focal_class.original_string: private final PreDiffPlan plan;
focal_class.type: PreDiffPlan
focal_class.var_name: plan
focal_class.declarator: deltaFriendlyOldFileSize
focal_class.modifier: private final
focal_class.original_string: private final long deltaFriendlyOldFileSize;
focal_class.type: long
focal_class.var_name: deltaFriendlyOldFileSize
focal_class.declarator: deltaFriendlyNewFileSize
focal_class.modifier: private final
focal_class.original_string: private final long deltaFriendlyNewFileSize;
focal_class.type: long
focal_class.var_name: deltaFriendlyNewFileSize
focal_class.declarator: deltaFile
focal_class.modifier: private final
focal_class.original_string: private final File deltaFile;
focal_class.type: File
focal_class.var_name: deltaFile
focal_class.file: feya/libraries/archive_diff/diff.generator/src/main/java/com/google/archivepatcher/generator/PatchWriter.java
focal_class.identifier: PatchWriter
focal_class.class_method_signature: PatchWriter.PatchWriter(
        PreDiffPlan plan,
        long deltaFriendlyOldFileSize,
        long deltaFriendlyNewFileSize,
        File deltaFile)
focal_class.full_signature: public  PatchWriter(
        PreDiffPlan plan,
        long deltaFriendlyOldFileSize,
        long deltaFriendlyNewFileSize,
        File deltaFile)
focal_class.identifier: PatchWriter
focal_class.modifiers: public
focal_class.parameters: (
        PreDiffPlan plan,
        long deltaFriendlyOldFileSize,
        long deltaFriendlyNewFileSize,
        File deltaFile)
focal_class.signature:  PatchWriter(
        PreDiffPlan plan,
        long deltaFriendlyOldFileSize,
        long deltaFriendlyNewFileSize,
        File deltaFile)
focal_class.class_method_signature: PatchWriter.writeV1Patch(OutputStream out)
focal_class.full_signature: public void writeV1Patch(OutputStream out)
focal_class.identifier: writeV1Patch
focal_class.modifiers: public
focal_class.parameters: (OutputStream out)
focal_class.return: void
focal_class.signature: void writeV1Patch(OutputStream out)
focal_method.body: public void writeV1Patch(OutputStream out) throws IOException {
      // Use DataOutputStream for ease of writing. This is deliberately left open, as closing it would
      // close the output stream that was passed in and that is not part of the method's documented
      // behavior.
      @SuppressWarnings("resource")
      DataOutputStream dataOut = new DataOutputStream(out);
  
      dataOut.write(PatchConstants.IDENTIFIER.getBytes("US-ASCII"));
      dataOut.writeInt(0); // Flags (reserved)
      dataOut.writeLong(deltaFriendlyOldFileSize);
  
      // Write out all the delta-friendly old file uncompression instructions
      dataOut.writeInt(plan.getOldFileUncompressionPlan().size());
      for (TypedRange<Void> range : plan.getOldFileUncompressionPlan()) {
        dataOut.writeLong(range.getOffset());
        dataOut.writeLong(range.getLength());
      }
  
      // Write out all the delta-friendly new file recompression instructions
      dataOut.writeInt(plan.getDeltaFriendlyNewFileRecompressionPlan().size());
      for (TypedRange<JreDeflateParameters> range : plan.getDeltaFriendlyNewFileRecompressionPlan()) {
        dataOut.writeLong(range.getOffset());
        dataOut.writeLong(range.getLength());
        // Write the deflate information
        dataOut.write(PatchConstants.CompatibilityWindowId.DEFAULT_DEFLATE.patchValue);
        dataOut.write(range.getMetadata().level);
        dataOut.write(range.getMetadata().strategy);
        dataOut.write(range.getMetadata().nowrap ? 1 : 0);
      }
  
      // Now the delta section
      // First write the number of deltas present in the patch. In v1, there is always exactly one
      // delta, and it is for the entire input; in future versions there may be multiple deltas, of
      // arbitrary types.
      dataOut.writeInt(1);
      // In v1 the delta format is always bsdiff, so write it unconditionally.
      dataOut.write(PatchConstants.DeltaFormat.BSDIFF.patchValue);
  
      // Write the working ranges. In v1 these are always the entire contents of the delta-friendly
      // old file and the delta-friendly new file. These are for forward compatibility with future
      // versions that may allow deltas of arbitrary formats to be mapped to arbitrary ranges.
      dataOut.writeLong(0); // i.e., start of the working range in the delta-friendly old file
      dataOut.writeLong(deltaFriendlyOldFileSize); // i.e., length of the working range in old
      dataOut.writeLong(0); // i.e., start of the working range in the delta-friendly new file
      dataOut.writeLong(deltaFriendlyNewFileSize); // i.e., length of the working range in new
  
      // Finally, the length of the delta and the delta itself.
      dataOut.writeLong(deltaFile.length());
      try (FileInputStream deltaFileIn = new FileInputStream(deltaFile);
          BufferedInputStream deltaIn = new BufferedInputStream(deltaFileIn)) {
        byte[] buffer = new byte[32768];
        int numRead = 0;
        while ((numRead = deltaIn.read(buffer)) >= 0) {
          dataOut.write(buffer, 0, numRead);
        }
      }
      dataOut.flush();
    }
focal_method.class_method_signature: PatchWriter.writeV1Patch(OutputStream out)
focal_method.full_signature: public void writeV1Patch(OutputStream out)
focal_method.identifier: writeV1Patch
focal_method.invocations: write getBytes writeInt writeLong writeInt size getOldFileUncompressionPlan getOldFileUncompressionPlan writeLong getOffset writeLong getLength writeInt size getDeltaFriendlyNewFileRecompressionPlan getDeltaFriendlyNewFileRecompressionPlan writeLong getOffset writeLong getLength write write getMetadata write getMetadata write getMetadata writeInt write writeLong writeLong writeLong writeLong writeLong length read write flush
focal_method.modifiers: public
focal_method.parameters: (OutputStream out)
focal_method.return: void
focal_method.signature: void writeV1Patch(OutputStream out)