You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/01/12 04:10:10 UTC
[38/50] [abbrv] kylin git commit: minor,
move duplicated ByteBufferBackedInputStream to common package
minor, move duplicated ByteBufferBackedInputStream to common package
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/b0aadb12
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/b0aadb12
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/b0aadb12
Branch: refs/heads/master-cdh5.7
Commit: b0aadb12d1e25005445eda0d912c63a941ad929a
Parents: 3a36c66
Author: gaodayue <ga...@meituan.com>
Authored: Tue Jan 10 11:51:38 2017 +0800
Committer: gaodayue <ga...@meituan.com>
Committed: Tue Jan 10 11:52:04 2017 +0800
----------------------------------------------------------------------
.../util/ByteBufferBackedInputStream.java | 61 ++++++++++++++++++++
.../kylin/measure/bitmap/BitmapCounter.java | 38 +-----------
.../measure/bitmap/BitmapAggregatorTest.java | 2 +-
.../kylin/measure/bitmap/BitmapCounterTest.java | 2 +-
.../measure/bitmap/BitmapSerializerTest.java | 2 +-
.../source/kafka/TimedJsonStreamParser.java | 2 +-
.../kafka/util/ByteBufferBackedInputStream.java | 52 -----------------
7 files changed, 66 insertions(+), 93 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/core-common/src/main/java/org/apache/kylin/common/util/ByteBufferBackedInputStream.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/util/ByteBufferBackedInputStream.java b/core-common/src/main/java/org/apache/kylin/common/util/ByteBufferBackedInputStream.java
new file mode 100644
index 0000000..7332ff2
--- /dev/null
+++ b/core-common/src/main/java/org/apache/kylin/common/util/ByteBufferBackedInputStream.java
@@ -0,0 +1,61 @@
+/*
+ * 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.kylin.common.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * Utility to view content available in a {@link ByteBuffer} as a {@link InputStream}.
+ *
+ * <b>Not thread-safe</b>
+ */
+public class ByteBufferBackedInputStream extends InputStream {
+ private final ByteBuffer buffer;
+
+ public ByteBufferBackedInputStream(ByteBuffer buffer) {
+ this.buffer = buffer;
+ }
+
+ @Override
+ public int available() throws IOException {
+ return buffer.remaining();
+ }
+
+ @Override
+ public int read() throws IOException {
+ return buffer.hasRemaining() ? (buffer.get() & 0xFF) : -1;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (len == 0) {
+ return 0;
+ }
+
+ if (!buffer.hasRemaining()) {
+ return -1;
+ }
+
+ len = Math.min(buffer.remaining(), len);
+ buffer.get(b, off, len);
+ return len;
+ }
+}
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java b/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
index 43ee506..19d7f5d 100644
--- a/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
+++ b/core-metadata/src/main/java/org/apache/kylin/measure/bitmap/BitmapCounter.java
@@ -22,10 +22,10 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Iterator;
+import org.apache.kylin.common.util.ByteBufferBackedInputStream;
import org.roaringbitmap.buffer.MutableRoaringBitmap;
/**
@@ -84,18 +84,6 @@ public class BitmapCounter implements Comparable<BitmapCounter>, java.io.Seriali
count = null;
}
- public void add(byte[] value) {
- add(value, 0, value.length);
- }
-
- public void add(byte[] value, int offset, int length) {
- if (value == null || length == 0) {
- return;
- }
-
- add(new String(value, offset, length));
- }
-
public void add(String value) {
if (value == null || value.isEmpty()) {
return;
@@ -235,29 +223,5 @@ public class BitmapCounter implements Comparable<BitmapCounter>, java.io.Seriali
else
return -1;
}
-
- private class ByteBufferBackedInputStream extends InputStream {
- private final ByteBuffer buffer;
-
- private ByteBufferBackedInputStream(ByteBuffer buf) {
- buffer = buf;
- }
-
- @Override
- public int read() throws IOException {
- return buffer.hasRemaining() ? (buffer.get() & 0xFF) : -1;
- }
-
- @Override
- public int read(byte[] bytes, int off, int len) throws IOException {
- if (!buffer.hasRemaining()) {
- return -1;
- }
-
- len = Math.min(len, buffer.remaining());
- buffer.get(bytes, off, len);
- return len;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapAggregatorTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapAggregatorTest.java b/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapAggregatorTest.java
index a930db7..e216d0b 100644
--- a/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapAggregatorTest.java
+++ b/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapAggregatorTest.java
@@ -33,7 +33,7 @@ public class BitmapAggregatorTest {
BitmapCounter counter = new BitmapCounter();
counter.add(1);
counter.add(3333);
- counter.add("123".getBytes());
+ counter.add("123");
counter.add(123);
assertEquals(3, counter.getCount());
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapCounterTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapCounterTest.java b/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapCounterTest.java
index f7796c0..c9c1b51 100644
--- a/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapCounterTest.java
+++ b/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapCounterTest.java
@@ -35,7 +35,7 @@ public class BitmapCounterTest {
BitmapCounter counter = new BitmapCounter();
counter.add(1);
counter.add(3333);
- counter.add("123".getBytes());
+ counter.add("123");
counter.add(123);
assertEquals(3, counter.getCount());
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapSerializerTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapSerializerTest.java b/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapSerializerTest.java
index 97b86ed..41efb2c 100644
--- a/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapSerializerTest.java
+++ b/core-metadata/src/test/java/org/apache/kylin/measure/bitmap/BitmapSerializerTest.java
@@ -47,7 +47,7 @@ public class BitmapSerializerTest extends LocalFileMetadataTestCase {
BitmapCounter counter = new BitmapCounter();
counter.add(1);
counter.add(3333);
- counter.add("123".getBytes());
+ counter.add("123");
counter.add(123);
assertEquals(3, counter.getCount());
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/source-kafka/src/main/java/org/apache/kylin/source/kafka/TimedJsonStreamParser.java
----------------------------------------------------------------------
diff --git a/source-kafka/src/main/java/org/apache/kylin/source/kafka/TimedJsonStreamParser.java b/source-kafka/src/main/java/org/apache/kylin/source/kafka/TimedJsonStreamParser.java
index e00ce16..6ff0d2f 100644
--- a/source-kafka/src/main/java/org/apache/kylin/source/kafka/TimedJsonStreamParser.java
+++ b/source-kafka/src/main/java/org/apache/kylin/source/kafka/TimedJsonStreamParser.java
@@ -31,9 +31,9 @@ import java.util.Arrays;
import com.fasterxml.jackson.databind.DeserializationFeature;
import org.apache.commons.lang3.StringUtils;
+import org.apache.kylin.common.util.ByteBufferBackedInputStream;
import org.apache.kylin.common.util.StreamingMessage;
import org.apache.kylin.metadata.model.TblColRef;
-import org.apache.kylin.source.kafka.util.ByteBufferBackedInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/kylin/blob/b0aadb12/source-kafka/src/main/java/org/apache/kylin/source/kafka/util/ByteBufferBackedInputStream.java
----------------------------------------------------------------------
diff --git a/source-kafka/src/main/java/org/apache/kylin/source/kafka/util/ByteBufferBackedInputStream.java b/source-kafka/src/main/java/org/apache/kylin/source/kafka/util/ByteBufferBackedInputStream.java
deleted file mode 100644
index 894a144..0000000
--- a/source-kafka/src/main/java/org/apache/kylin/source/kafka/util/ByteBufferBackedInputStream.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.kylin.source.kafka.util;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-
-/**
- */
-public class ByteBufferBackedInputStream extends InputStream {
-
- private ByteBuffer buf;
-
- public ByteBufferBackedInputStream(ByteBuffer buf) {
- this.buf = buf;
- }
-
- @Override
- public int read() throws IOException {
- if (!buf.hasRemaining()) {
- return -1;
- }
- return buf.get() & 0xFF;
- }
-
- @Override
- public int read(byte[] bytes, int off, int len) throws IOException {
- if (!buf.hasRemaining()) {
- return -1;
- }
-
- len = Math.min(len, buf.remaining());
- buf.get(bytes, off, len);
- return len;
- }
-}