Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.DataAccess


    bundleFile = bundle;
    fnDecorer = Internals.buildFileNameEncodingHelper(new SessionContext.SourcePrim(ctx));
  }

  private DataAccess getDataStream() throws IOException {
    DataAccess da = accessProvider.createReader(bundleFile, false);
    byte[] signature = new byte[6];
    if (da.length() > 6) {
      da.readBytes(signature, 0, 6);
      if (signature[0] == 'H' && signature[1] == 'G' && signature[2] == '1' && signature[3] == '0') {
        if (signature[4] == 'G' && signature[5] == 'Z') {
          return new InflaterDataAccess(da, 6, da.length() - 6);
        }
        if (signature[4] == 'B' && signature[5] == 'Z') {
          throw Internals.notImplemented();
        }
        if (signature[4] != 'U' || signature[5] != 'N') {
          throw new HgInvalidStateException(String.format("Bad bundle signature: %s",  String.valueOf(signature)));
        }
        // "...UN", fall-through
      } else {
        da.reset();
      }
    }
    return da;
  }
View Full Code Here


  public void inspectChangelog(Inspector inspector) throws HgIOException, HgRuntimeException {
    if (inspector == null) {
      throw new IllegalArgumentException();
    }
    final Lifecycle lifecycle = lifecycleSetUp(inspector);
    DataAccess da = null;
    try {
      da = getDataStream();
      internalInspectChangelog(da, inspector);
    } catch (IOException ex) {
      throw new HgIOException("Failed to inspect changelog in the bundle", ex, bundleFile);
    } finally {
      if (da != null) {
        da.done();
      }
      lifecycleTearDown(lifecycle);
    }
  }
View Full Code Here

  public void inspectManifest(Inspector inspector) throws HgIOException, HgRuntimeException {
    if (inspector == null) {
      throw new IllegalArgumentException();
    }
    final Lifecycle lifecycle = lifecycleSetUp(inspector);
    DataAccess da = null;
    try {
      da = getDataStream();
      if (da.isEmpty()) {
        return;
      }
      skipGroup(da); // changelog
      internalInspectManifest(da, inspector);
    } catch (IOException ex) {
      throw new HgIOException("Failed to inspect manifest in the bundle", ex, bundleFile);
    } finally {
      if (da != null) {
        da.done();
      }
      lifecycleTearDown(lifecycle);
    }
  }
View Full Code Here

  public void inspectFiles(Inspector inspector) throws HgIOException, HgRuntimeException {
    if (inspector == null) {
      throw new IllegalArgumentException();
    }
    final Lifecycle lifecycle = lifecycleSetUp(inspector);
    DataAccess da = null;
    try {
      da = getDataStream();
      if (da.isEmpty()) {
        return;
      }
      skipGroup(da); // changelog
      if (da.isEmpty()) {
        return;
      }
      skipGroup(da); // manifest
      internalInspectFiles(da, inspector);
    } catch (IOException ex) {
      throw new HgIOException("Failed to inspect files in the bundle", ex, bundleFile);
    } finally {
      if (da != null) {
        da.done();
      }
      lifecycleTearDown(lifecycle);
    }
  }
View Full Code Here

  public void inspectAll(Inspector inspector) throws HgIOException, HgRuntimeException {
    if (inspector == null) {
      throw new IllegalArgumentException();
    }
    final Lifecycle lifecycle = lifecycleSetUp(inspector);
    DataAccess da = null;
    try {
      da = getDataStream();
      internalInspectChangelog(da, inspector);
      if (flowControl.isStopped()) {
        return;
      }
      internalInspectManifest(da, inspector);
      if (flowControl.isStopped()) {
        return;
      }
      internalInspectFiles(da, inspector);
    } catch (IOException ex) {
      throw new HgIOException("Failed to inspect bundle", ex, bundleFile);
    } finally {
      if (da != null) {
        da.done();
      }
      lifecycleTearDown(lifecycle);
    }
  }
View Full Code Here

      byte[] nb = new byte[80];
      da.readBytes(nb, 0, 80);
      int dataLength = len - 84 /* length field + 4 nodeids */;
      byte[] data = new byte[dataLength];
      da.readBytes(data, 0, dataLength);
      DataAccess slice = new ByteArrayDataAccess(data); // XXX in fact, may pass a slicing DataAccess.
      // Just need to make sure that we seek to proper location afterwards (where next GroupElement starts),
      // regardless whether that slice has read it or not.
      GroupElement ge = new GroupElement(nb, prevNodeid, slice);
      good2go = inspector.element(ge);
      slice.done(); // BADA doesn't implement done(), but it could (e.g. free array)
      /// and we'd better tell it we are not going to use it any more. However, it's important to ensure Inspector
      // implementations out there do not retain GroupElement.rawData()
      prevNodeid = ge.node();
      len = da.isEmpty() ? 0 : da.readInt();
    }
View Full Code Here

        boolean writeComplete = false;
        Nodeid deltaBase = ge.patchBase();
        if (deltaBase.isNull()) {
          // NOTE, can't use both parents isNull == true to empty prevRevContent
          // see build.gradle sample below why.
          prevRevContent = new DataAccess(); // empty data
          writeComplete = true;
          // if (writeComplete) would set baseRevision correctly,
        } else {
          Nodeid prevRevision = revisionSequence.size() > 0 ? revisionSequence.get(revisionSequence.size()-1) : Nodeid.NULL;
          if (!prevRevision.equals(deltaBase)) {
View Full Code Here

    return new ByteArrayDataAccess(bos.toByteArray());
  }
 
  @Test
  public void testSeek() throws Exception {
    DataAccess zip = zip(testContent1);
    InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    ida.seek(20);
    final int bufferCapacity = 10;
    ByteBuffer chunk1 = ByteBuffer.allocate(bufferCapacity);
    ida.readBytes(chunk1);
    errorCollector.assertTrue(new ByteArraySlice(testContent1, 20, bufferCapacity).equalsTo(chunk1.array()));
View Full Code Here

    errorCollector.assertEquals(chunk1, chunk2);
  }
 
  @Test
  public void testLength() throws Exception {
    DataAccess zip = zip(testContent1);
    InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    errorCollector.assertEquals("Plain #length()", testContent1.length, ida.length());
    //
    ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    byte[] dummy = new byte[30];
    ida.readBytes(dummy, 0, dummy.length);
    errorCollector.assertEquals("#length() after readBytes()", testContent1.length, ida.length());
    //
    ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    // consume most of the stream, so that all original compressed data is already read
    dummy = new byte[testContent1.length - 1];
    ida.readBytes(dummy, 0, dummy.length);
    errorCollector.assertEquals("#length() after origin was completely read", testContent1.length, ida.length());
    //
View Full Code Here

    errorCollector.assertFalse(ida.isEmpty()); // check InflaterDataAccess#available() positive
  }

  @Test
  public void testReadBytes() throws Exception {
    DataAccess zip = zip(testContent1);
    InflaterDataAccess ida = new InflaterDataAccess(zip, 0, zip.length(), -1, new Inflater(), new byte[25], null);
    ida.skip(10);
    byte[] chunk1 = new byte[22];
    ida.readBytes(chunk1, 0, 20);
    chunk1[20] = ida.readByte();
    chunk1[21] = ida.readByte();
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.DataAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.