You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2017/10/14 12:14:44 UTC
[10/19] commons-io git commit: [IO-507] Add a ByteOrderParser class.
[IO-507] Add a ByteOrderParser class.
Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/7379cbb2
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/7379cbb2
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/7379cbb2
Branch: refs/heads/release
Commit: 7379cbb2fe7b69aa871127e64a51763c445a570e
Parents: fa24ac8
Author: Benedikt Ritter <br...@apache.org>
Authored: Fri Oct 13 18:02:05 2017 -0600
Committer: ggregory <gg...@apache.org>
Committed: Fri Oct 13 18:02:05 2017 -0600
----------------------------------------------------------------------
src/changes/changes.xml | 2 +-
.../org/apache/commons/io/ByteOrderParser.java | 67 ++++++++++++++++
.../org/apache/commons/io/ByteOrderUtils.java | 82 --------------------
.../apache/commons/io/ByteOrderParserTest.java | 44 +++++++++++
.../apache/commons/io/ByteOrderUtilsTest.java | 43 ----------
5 files changed, 112 insertions(+), 126 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-io/blob/7379cbb2/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6372483..bfc9c25 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -114,7 +114,7 @@ The <action> type attribute can be add,update,fix,remove.
Add infinite circular input stream
</action>
<action issue="IO-507" dev="ggregory" type="add">
- Add a ByteOrderUtils class.
+ Add a ByteOrderParser class.
</action>
<action issue="IO-518" dev="jochen" type="add">
Add ObservableInputStream
http://git-wip-us.apache.org/repos/asf/commons-io/blob/7379cbb2/src/main/java/org/apache/commons/io/ByteOrderParser.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/ByteOrderParser.java b/src/main/java/org/apache/commons/io/ByteOrderParser.java
new file mode 100644
index 0000000..9e7d298
--- /dev/null
+++ b/src/main/java/org/apache/commons/io/ByteOrderParser.java
@@ -0,0 +1,67 @@
+/*
+ * 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.commons.io;
+
+import java.nio.ByteOrder;
+import java.util.Locale;
+
+/**
+ * Converts Strings to {@link ByteOrder} instances.
+ *
+ * @since 2.6
+ */
+public final class ByteOrderParser {
+
+ /**
+ * ByteOrderUtils is a static utility class, so prevent construction with a private constructor.
+ */
+ private ByteOrderParser() {
+ }
+
+ /**
+ * Parses the String argument as a {@link ByteOrder}, ignoring case.
+ * <p>
+ * Returns {@code ByteOrder.LITTLE_ENDIAN} if the given value is {@code "LITTLE_ENDIAN"}.
+ * </p>
+ * <p>
+ * Returns {@code ByteOrder.BIG_ENDIAN} if the given value is {@code "BIG_ENDIAN"}.
+ * </p>
+ * Examples:
+ * <ul>
+ * <li>{@code ByteOrderParser.parseByteOrder("LITTLE_ENDIAN")} returns {@code ByteOrder.LITTLE_ENDIAN}</li>
+ * <li>{@code ByteOrderParser.parseByteOrder("BIG_ENDIAN")} returns {@code ByteOrder.BIG_ENDIAN}</li>
+ * </ul>
+ *
+ * @param value
+ * the {@code String} containing the ByteOrder representation to be parsed
+ * @return the ByteOrder represented by the string argument
+ * @throws IllegalArgumentException
+ * if the {@code String} containing the ByteOrder representation to be parsed is unknown.
+ */
+ public static ByteOrder parseByteOrder(final String value) {
+ if (ByteOrder.BIG_ENDIAN.toString().equals(value)) {
+ return ByteOrder.BIG_ENDIAN;
+ }
+ if (ByteOrder.LITTLE_ENDIAN.toString().equals(value)) {
+ return ByteOrder.LITTLE_ENDIAN;
+ }
+ throw new IllegalArgumentException("Unsupported byte order setting: " + value + ", expeced one of " + ByteOrder.LITTLE_ENDIAN +
+ ", " + ByteOrder.BIG_ENDIAN);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/commons-io/blob/7379cbb2/src/main/java/org/apache/commons/io/ByteOrderUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/ByteOrderUtils.java b/src/main/java/org/apache/commons/io/ByteOrderUtils.java
deleted file mode 100644
index 96ca446..0000000
--- a/src/main/java/org/apache/commons/io/ByteOrderUtils.java
+++ /dev/null
@@ -1,82 +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.commons.io;
-
-import java.nio.ByteOrder;
-import java.util.Locale;
-
-/**
- * Converts Strings to {@link ByteOrder} instances.
- *
- * @since 2.6
- */
-public final class ByteOrderUtils {
-
- private static final Locale ComparisonLocale = Locale.ROOT;
-
- /**
- * Big endian.
- */
- public static final String BIG_ENDIAN = "Big";
-
- /**
- * Little endian.
- */
- public static final String LITTLE_ENDIAN = "Little";
-
- /**
- * ByteOrderUtils is a static utility class, so prevent construction with a private constructor.
- */
- private ByteOrderUtils() {
- }
-
- /**
- * Parses the String argument as a {@link ByteOrder}, ignoring case.
- * <p>
- * Returns {@code ByteOrder.LITTLE_ENDIAN} if the given value is {@code "little"} or {@code "LITTLE_ENDIAN"}.
- * </p>
- * <p>
- * Returns {@code ByteOrder.BIG_ENDIAN} if the given value is {@code "big"} or {@code "BIG_ENDIAN"}.
- * </p>
- * Examples:
- * <ul>
- * <li>{@code ByteOrderUtils.parseByteOrder("little")} returns {@code ByteOrder.LITTLE_ENDIAN}</li>
- * <li>{@code ByteOrderUtils.parseByteOrder("big")} returns {@code ByteOrder.BIG_ENDIAN}</li>
- * </ul>
- *
- * @param value
- * the {@code String} containing the ByteOrder representation to be parsed
- * @return the ByteOrder represented by the string argument
- * @throws IllegalArgumentException
- * if the {@code String} containing the ByteOrder representation to be parsed is unknown.
- */
- public static ByteOrder parseByteOrder(final String value) {
- final String valueUp = value.toUpperCase(ComparisonLocale);
- final String bigEndianUp = BIG_ENDIAN.toUpperCase(ComparisonLocale);
- final String littleEndianUp = LITTLE_ENDIAN.toUpperCase(ComparisonLocale);
- if (bigEndianUp.equals(valueUp) || ByteOrder.BIG_ENDIAN.toString().equals(valueUp)) {
- return ByteOrder.BIG_ENDIAN;
- }
- if (littleEndianUp.equals(valueUp) || ByteOrder.LITTLE_ENDIAN.toString().equals(valueUp)) {
- return ByteOrder.LITTLE_ENDIAN;
- }
- throw new IllegalArgumentException("Unsupported byte order setting: " + value + ", expeced one of " + ByteOrder.LITTLE_ENDIAN + ", " +
- LITTLE_ENDIAN + ", " + ByteOrder.BIG_ENDIAN + ", " + bigEndianUp);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/commons-io/blob/7379cbb2/src/test/java/org/apache/commons/io/ByteOrderParserTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/ByteOrderParserTest.java b/src/test/java/org/apache/commons/io/ByteOrderParserTest.java
new file mode 100644
index 0000000..a3310d4
--- /dev/null
+++ b/src/test/java/org/apache/commons/io/ByteOrderParserTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.commons.io;
+
+import java.nio.ByteOrder;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ByteOrderParserTest {
+
+ private ByteOrder parseByteOrder(final String value) {
+ return ByteOrderParser.parseByteOrder(value);
+ }
+
+ @Test
+ public void testParseBig() {
+ Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("BIG_ENDIAN"));
+ }
+
+ @Test
+ public void testParseLittle() {
+ Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("LITTLE_ENDIAN"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testThrowsException() throws Exception {
+ parseByteOrder("some value");
+ }
+}
http://git-wip-us.apache.org/repos/asf/commons-io/blob/7379cbb2/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java b/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java
deleted file mode 100644
index 2affec4..0000000
--- a/src/test/java/org/apache/commons/io/ByteOrderUtilsTest.java
+++ /dev/null
@@ -1,43 +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.commons.io;
-
-import java.nio.ByteOrder;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ByteOrderUtilsTest {
-
- private ByteOrder parseByteOrder(final String value) {
- return ByteOrderUtils.parseByteOrder(value);
- }
-
- @Test
- public void testParseBig() {
- Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("big"));
- Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("Big"));
- Assert.assertEquals(ByteOrder.BIG_ENDIAN, parseByteOrder("BIG"));
- }
-
- @Test
- public void testParseLittle() {
- Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("little"));
- Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("Little"));
- Assert.assertEquals(ByteOrder.LITTLE_ENDIAN, parseByteOrder("LITTLE"));
- }
-}