类org.apache.zookeeper.server.ByteBufferInputStream源码实例Demo

下面列出了怎么用org.apache.zookeeper.server.ByteBufferInputStream的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lucene-solr   文件: PackageStoreAPI.java
private void validate(List<String> sigs,
                      ByteBuffer buf) throws SolrException, IOException {
  Map<String, byte[]> keys = packageStore.getKeys();
  if (keys == null || keys.isEmpty()) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
        "package store does not have any keys");
  }
  CryptoKeys cryptoKeys = null;
  try {
    cryptoKeys = new CryptoKeys(keys);
  } catch (Exception e) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
        "Error parsing public keys in Package store");
  }
  for (String sig : sigs) {
    if (cryptoKeys.verify(sig, buf) == null) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Signature does not match any public key : " + sig +" len: "+buf.limit()+  " content sha512: "+
          DigestUtils.sha512Hex(new ByteBufferInputStream(buf)));
    }

  }
}
 
源代码2 项目: lucene-solr   文件: TestDistribPackageStore.java
@SuppressWarnings({"unchecked", "rawtypes"})
public static void waitForAllNodesHaveFile(MiniSolrCloudCluster cluster, String path, Map expected , boolean verifyContent) throws Exception {
  for (JettySolrRunner jettySolrRunner : cluster.getJettySolrRunners()) {
    String baseUrl = jettySolrRunner.getBaseUrl().toString().replace("/solr", "/api");
    String url = baseUrl + "/node/files" + path + "?wt=javabin&meta=true";
    assertResponseValues(10, new Fetcher(url, jettySolrRunner), expected);

    if(verifyContent) {
      try (HttpSolrClient solrClient = (HttpSolrClient) jettySolrRunner.newClient()) {
        ByteBuffer buf = Utils.executeGET(solrClient.getHttpClient(), baseUrl + "/node/files" + path,
            Utils.newBytesConsumer(Integer.MAX_VALUE));
        assertEquals(
            "d01b51de67ae1680a84a813983b1de3b592fc32f1a22b662fc9057da5953abd1b72476388ba342cad21671cd0b805503c78ab9075ff2f3951fdf75fa16981420",
            DigestUtils.sha512Hex(new ByteBufferInputStream(buf))
        );

      }
    }

  }
}
 
源代码3 项目: SpinalTap   文件: ColumnSerializationUtil.java
/**
 * mapping between column type to java type BIT => BitSet ENUM, YEAR TINY, SHORT, INT24, LONG =>
 * int SET, LONGLONG => long FLOAT => float DOUBLE => value NEWDECIMAL => BigDecimal DATE => Date
 * TIME, TIME_V2 => Time TIMESTAMP, TIMESTAMP_V2 => Timestmap DATETIME, DATETIME_V2 => Date case
 * YEAR: STRING, VARCHAR, VAR_STRING => String BLOB => byte[]
 */
public static Serializable deserializeColumn(
    @NonNull final Map<String, ByteBuffer> entity, @NonNull final String column) {
  final ByteBuffer byteBuffer = entity.get(column);

  if (byteBuffer == null) {
    return null;
  }

  final ByteBufferInputStream inputStream = new ByteBufferInputStream(byteBuffer);
  return (Serializable) SerializationUtils.deserialize(inputStream);
}
 
源代码4 项目: lucene-solr   文件: Utils.java
public static InputStream toJavabin(Object o) throws IOException {
  try (final JavaBinCodec jbc = new JavaBinCodec()) {
    BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS();
    jbc.marshal(o, baos);
    return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(), 0, baos.size()));
  }
}
 
源代码5 项目: lucene-solr   文件: PackageStoreAPI.java
/**
 * Creates a JSON string with the metadata
 * @lucene.internal
 */
public static MetaData _createJsonMetaData(ByteBuffer buf, List<String> signatures) throws IOException {
  String sha512 = DigestUtils.sha512Hex(new ByteBufferInputStream(buf));
  Map<String, Object> vals = new HashMap<>();
  vals.put(MetaData.SHA512, sha512);
  if (signatures != null) {
    vals.put("sig", signatures);
  }
  return new MetaData(vals);
}
 
源代码6 项目: xian   文件: ChaosMonkeyCnxnFactory.java
@Override
public void submitRequest(Request si)
{
    long remaining = firstError != 0 ? LOCKOUT_DURATION_MS - (System.currentTimeMillis() - firstError) : 0;
    if ( si.type != ZooDefs.OpCode.createSession && si.type != ZooDefs.OpCode.sync && si.type != ZooDefs.OpCode.ping
        && firstError != 0 && remaining > 0 )
    {
        log.debug("Rejected : " + si.toString());
        // Still reject request
        log.debug("Still not ready for " + remaining + "ms");
        ((NIOServerCnxn)si.cnxn).close();
        return;
    }
    // Submit the request to the legacy Zookeeper server
    log.debug("Applied : " + si.toString());
    super.submitRequest(si);
    // Raise an error if a lock is created
    if ( si.type == ZooDefs.OpCode.create )
    {
        CreateRequest createRequest = new CreateRequest();
        try
        {
            ByteBuffer duplicate = si.request.duplicate();
            duplicate.rewind();
            ByteBufferInputStream.byteBuffer2Record(duplicate, createRequest);
            if ( createRequest.getPath().startsWith(CHAOS_ZNODE_PREFIX)
                && firstError == 0 )
            {
                firstError = System.currentTimeMillis();
                // The znode has been created, close the connection and don't tell it to client
                log.warn("Closing connection right after " + createRequest.getPath() + " creation");
                ((NIOServerCnxn)si.cnxn).close();
            }
        }
        catch ( Exception e )
        {
            // Should not happen
            ((NIOServerCnxn)si.cnxn).close();
        }
    }
}
 
源代码7 项目: lucene-solr   文件: PackageStore.java
public InputStream getInputStream() {
  if (buf != null) return new ByteBufferInputStream(buf);
  return null;

}
 
源代码8 项目: lucene-solr   文件: ZookeeperInfoHandler.java
@Override
public InputStream getStream() throws IOException {
  return new ByteBufferInputStream(baos.getByteBuffer());
}
 
源代码9 项目: lucene-solr   文件: BlobRepository.java
public BlobContent(String key, ByteBuffer buffer, Decoder<T> decoder) {
  this.key = key;
  this.content = decoder == null ? (T) buffer : decoder.decode(new ByteBufferInputStream(buffer));
}
 
源代码10 项目: curator   文件: ChaosMonkeyCnxnFactory.java
@Override
public void submitRequest(Request si)
{
    long remaining = firstError != 0 ? LOCKOUT_DURATION_MS - (System.currentTimeMillis() - firstError) : 0;
    if ( si.type != ZooDefs.OpCode.createSession && si.type != ZooDefs.OpCode.sync && si.type != ZooDefs.OpCode.ping
        && firstError != 0 && remaining > 0 )
    {
        log.debug("Rejected : " + si.toString());
        // Still reject request
        log.debug("Still not ready for " + remaining + "ms");
        Compatibility.serverCnxnClose(si.cnxn);
        return;
    }
    // Submit the request to the legacy Zookeeper server
    log.debug("Applied : " + si.toString());
    super.submitRequest(si);
    // Raise an error if a lock is created
    if ( (si.type == ZooDefs.OpCode.create) || (si.type == ZooDefs.OpCode.create2) )
    {
        CreateRequest createRequest = new CreateRequest();
        try
        {
            ByteBuffer duplicate = si.request.duplicate();
            duplicate.rewind();
            ByteBufferInputStream.byteBuffer2Record(duplicate, createRequest);
            if ( createRequest.getPath().startsWith(CHAOS_ZNODE_PREFIX)
                && firstError == 0 )
            {
                firstError = System.currentTimeMillis();
                // The znode has been created, close the connection and don't tell it to client
                log.warn("Closing connection right after " + createRequest.getPath() + " creation");
                Compatibility.serverCnxnClose(si.cnxn);
            }
        }
        catch ( Exception e )
        {
            // Should not happen
            Compatibility.serverCnxnClose(si.cnxn);
        }
    }
}
 
 类所在包
 同包方法