flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From StephanEwen <...@git.apache.org>
Subject [GitHub] incubator-flink pull request: Integration of Daniel's BLOB manager
Date Fri, 03 Oct 2014 15:52:18 GMT
Github user StephanEwen commented on a diff in the pull request:

    https://github.com/apache/incubator-flink/pull/126#discussion_r18402567
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/blob/BlobKey.java ---
    @@ -0,0 +1,199 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +
    +package org.apache.flink.runtime.blob;
    +
    +import java.io.EOFException;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.io.OutputStream;
    +import java.security.MessageDigest;
    +import java.util.Arrays;
    +
    +import org.apache.flink.core.io.IOReadableWritable;
    +import org.apache.flink.core.memory.DataInputView;
    +import org.apache.flink.core.memory.DataOutputView;
    +
    +/**
    + * A BLOB key uniquely identifies a BLOB.
    + */
    +public final class BlobKey implements IOReadableWritable, Comparable<BlobKey> {
    +
    +	/**
    +	 * Array of hex characters to facilitate fast toString() method.
    +	 */
    +	private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
    +
    +	/**
    +	 * Size of the internal BLOB key in bytes.
    +	 */
    +	private static final int SIZE = 20;
    +
    +	/**
    +	 * The byte buffer storing the actual key data.
    +	 */
    +	private final byte[] key;
    +
    +	/**
    +	 * Constructs a new BLOB key.
    +	 */
    +	public BlobKey() {
    +		this.key = new byte[SIZE];
    +	}
    +
    +	/**
    +	 * Constructs a new BLOB key from the given byte array.
    +	 * 
    +	 * @param key
    +	 *        the actual key data
    +	 */
    +	BlobKey(final byte[] key) {
    +
    +		if (key.length != SIZE) {
    +			throw new IllegalArgumentException("BLOB key must have a size of " + SIZE + " bytes");
    +		}
    +
    +		this.key = key;
    +	}
    +
    +	/**
    +	 * {@inheritDoc}
    +	 */
    +	@Override
    +	public void write(final DataOutputView out) throws IOException {
    +		out.write(this.key);
    +	}
    +
    +	/**
    +	 * {@inheritDoc}
    +	 */
    +	@Override
    +	public void read(final DataInputView in) throws IOException {
    +		in.readFully(this.key);
    +	}
    +
    +	/**
    +	 * {@inheritDoc}
    +	 */
    +	@Override
    +	public boolean equals(final Object obj) {
    +
    +		if (!(obj instanceof BlobKey)) {
    +			return false;
    +		}
    +
    +		final BlobKey bk = (BlobKey) obj;
    +
    +		return Arrays.equals(this.key, bk.key);
    +	}
    +
    +	/**
    +	 * {@inheritDoc}
    +	 */
    +	@Override
    +	public int hashCode() {
    +		return Arrays.hashCode(this.key);
    +	}
    +
    +	/**
    +	 * {@inheritDoc}
    +	 */
    +	@Override
    +	public String toString() {
    +
    +		final char[] hexChars = new char[SIZE * 2];
    --- End diff --
    
    This seems to be a solution taken from stackoverflow. I think the code should attribute
that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message