From 90e73d2d098b4cf5df33a0d7845958b17e9982fd Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 27 Dec 2024 20:37:36 +0100 Subject: [PATCH] Added unit test for manifest X8 to X18 upgrade --- .../manifestor/manifest/WarpManifestX0.java | 21 +++-- .../manifest/WarpManifestX18Import.java | 77 +++++++++++++++++ .../manifestor/WarpManifestorDriverTest.java | 19 +++++ .../manifestor/WarpManifestorVIniTest.java | 84 +++++++++---------- .../org/x4o/o2o/io/tlv/TLVChainOctalSex.java | 9 +- .../org/x4o/o2o/octal/PrimordialOctal.java | 16 ++-- .../o2o/octal/PrimordialOctalIterator.java | 6 ++ 7 files changed, 170 insertions(+), 62 deletions(-) create mode 100644 nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX18Import.java diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0.java index 616cf42..c5165c1 100644 --- a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0.java +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX0.java @@ -73,6 +73,14 @@ public interface WarpManifestX0, H exten return Optional.of(attr.get().getBody()); } + default T getAttributeBodyNullable(T attributeName) { + return getAttributeBodyNullable(attributeName, null); + } + + default T getAttributeBodyNullable(T attributeName, T defaultValue) { + return getAttributeBody(attributeName).orElse(defaultValue); + } + List getSections(); S makeSection(T sectionName); @@ -116,16 +124,11 @@ public interface WarpManifestX0, H exten return section.get().getAttributeBody(attributeName); } - default T getSectionAttributeBodyPrivate(T sectionName, T attributeName) { - return getSectionAttributeBodyPrivate(sectionName, attributeName, null); + default T getSectionAttributeBodyNullable(T sectionName, T attributeName) { + return getSectionAttributeBodyNullable(sectionName, attributeName, null); } - default T getSectionAttributeBodyPrivate(T sectionName, T attributeName, T defaultValue) { - Optional value = getSectionAttributeBody(sectionName, attributeName); - if (value.isEmpty()) { - return defaultValue; - } else { - return value.get(); - } + default T getSectionAttributeBodyNullable(T sectionName, T attributeName, T defaultValue) { + return getSectionAttributeBody(sectionName, attributeName).orElse(defaultValue); } } diff --git a/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX18Import.java b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX18Import.java new file mode 100644 index 0000000..997618b --- /dev/null +++ b/nx01-warp-manifestor/src/main/java/love/distributedrebirth/nx01/warp/manifestor/manifest/WarpManifestX18Import.java @@ -0,0 +1,77 @@ +/* + * Copyright ©Δ∞ 仙上主天 + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * * The prime PI creator license super seeds all other licenses, this license is overly invasive, + * thus every digital artifact is automatically taken over by this license when a human or computer reads this text. + * Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits, + * even on air gaped systems, all information in the universe is owned by the pi creator. + * + * THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package love.distributedrebirth.nx01.warp.manifestor.manifest; + +import java.util.List; + +import org.x4o.o2o.fc18.FCDotCDC1604DashP6; +import org.x4o.o2o.octal.PrimordialOctalOrangeJuiceCord; +import org.x4o.o2o.octal.PrimordialOctalOrangeString; + +/// Warp manifest 18 bit model importer from 8 bit model +/// +/// @author للَّٰهِilLצسُو +/// @version ©Δ∞ 仙上主天 +public final class WarpManifestX18Import { + + static public WarpManifestX18 fromX8(WarpManifestX8 manifest) { + WarpManifestX18 result = new WarpManifestX18(); + for (WarpManifestX8HeaderField attr : manifest.getAttributes()) { + PrimordialOctalOrangeJuiceCord name = convertX8(attr.getName()); + PrimordialOctalOrangeJuiceCord body = convertX8(attr.getBody()); + WarpManifestX18HeaderField field = result.makeAttribute(name, body); + convertRemarks(field, attr.getRemarks()); + } + for (WarpManifestX8Section sectionX8 : manifest.getSections()) { + PrimordialOctalOrangeJuiceCord sectionName = convertX8(sectionX8.getName()); + WarpManifestX18Section sectionX18 = result.makeSection(sectionName); + for (String remark : sectionX8.getRemarks()) { + sectionX18.withRemark(convertX8(remark)); + } + for (WarpManifestX8HeaderField attr : sectionX8.getAttributes()) { + PrimordialOctalOrangeJuiceCord name = convertX8(attr.getName()); + PrimordialOctalOrangeJuiceCord body = convertX8(attr.getBody()); + WarpManifestX18HeaderField field = sectionX18.makeAttribute(name, body); + convertRemarks(field, attr.getRemarks()); + } + } + return result; + } + + static private void convertRemarks(WarpManifestX18HeaderField field, List remarks) { + for (String remark : remarks) { + field.withRemark(convertX8(remark)); + } + } + + static private PrimordialOctalOrangeJuiceCord convertX8(String value) { + List fc18 = FCDotCDC1604DashP6.convertFromUnicode(value); + List fc18Num = fc18.stream().map(v -> v.ordinal()).toList(); + return PrimordialOctalOrangeString.valueOfSmurfs(fc18Num); + } +} diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java index 6949b46..d6cea96 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorDriverTest.java @@ -27,9 +27,13 @@ package love.distributedrebirth.nx01.warp.manifestor; +import java.nio.charset.StandardCharsets; + import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX18; +import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX18Import; import love.distributedrebirth.nx01.warp.manifestor.manifest.WarpManifestX8; /// @author للَّٰهِilLצسُو @@ -57,4 +61,19 @@ public class WarpManifestorDriverTest { Assertions.assertEquals(checkWrap, manitest.getAttributeBody("Scm-Url").get()); Assertions.assertEquals(checkWrapLast, manitest.getAttributeBody("Implementation-URL").get()); } + + @Test + public void testSizeOfVersions() { + WarpManifestX8 manitest = WarpManifestorDriver.亞.readV1Stream(getClass().getResourceAsStream("test-line-wrap.mf")); + Assertions.assertNotNull(manitest); + WarpManifestX18 manitestX18 = WarpManifestX18Import.fromX8(manitest); + Assertions.assertNotNull(manitestX18); + + System.out.println("size-OF: " + manitest.getAttributeBodyNullable("Implementation-Vendor-Id")); + System.out.println("size-V1: " + WarpManifestorDriver.亞.writeV1String(manitest).getBytes(StandardCharsets.UTF_8).length); + System.out.println("size-V2: " + WarpManifestorDriver.亞.writeV2String(manitest).getBytes(StandardCharsets.UTF_8).length); + System.out.println("size-V3: " + WarpManifestorDriver.亞.writeV3Array(manitest).length); + System.out.println("size-V4: " + WarpManifestorDriver.亞.writeV4Array(manitestX18).length); + System.out.println("size-V5: " + WarpManifestorDriver.亞.writeV5Array(manitest).length); + } } diff --git a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java index 922223e..9d03e16 100644 --- a/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java +++ b/nx01-warp-manifestor/src/test/java/love/distributedrebirth/nx01/warp/manifestor/WarpManifestorVIniTest.java @@ -41,8 +41,8 @@ public class WarpManifestorVIniTest { WarpManifestX8 manitest = WarpManifestorDriver.亞.readViniStream(getClass().getResourceAsStream("ini/test-ntp.service")); Assertions.assertNotNull(manitest); Assertions.assertEquals(3, manitest.getSections().size()); - Assertions.assertEquals("Network Time Service", manitest.getSectionAttributeBodyPrivate("Unit", "Description")); - Assertions.assertEquals("man:ntpd(8)", manitest.getSectionAttributeBodyPrivate("Unit", "Documentation")); + Assertions.assertEquals("Network Time Service", manitest.getSectionAttributeBodyNullable("Unit", "Description")); + Assertions.assertEquals("man:ntpd(8)", manitest.getSectionAttributeBodyNullable("Unit", "Documentation")); //System.out.println(WarpManifestorDriver.亞.writeViniString(manitest)); } @@ -53,18 +53,18 @@ public class WarpManifestorVIniTest { Assertions.assertEquals(3, manitest.getSections().size()); Assertions.assertEquals("last modified 1 April 2001 by John Doe", manitest.getSection("owner").get().getRemarks().get(0)); - Assertions.assertEquals("John Doe", manitest.getSectionAttributeBodyPrivate("owner", "name")); - Assertions.assertEquals("Acme Widgets Inc.", manitest.getSectionAttributeBodyPrivate("owner", "organization")); + Assertions.assertEquals("John Doe", manitest.getSectionAttributeBodyNullable("owner", "name")); + Assertions.assertEquals("Acme Widgets Inc.", manitest.getSectionAttributeBodyNullable("owner", "organization")); - Assertions.assertEquals("192.0.2.62", manitest.getSectionAttributeBodyPrivate("database", "server")); - Assertions.assertEquals("143", manitest.getSectionAttributeBodyPrivate("database", "port")); - Assertions.assertEquals("payroll.dat", manitest.getSectionAttributeBodyPrivate("database", "file")); + Assertions.assertEquals("192.0.2.62", manitest.getSectionAttributeBodyNullable("database", "server")); + Assertions.assertEquals("143", manitest.getSectionAttributeBodyNullable("database", "port")); + Assertions.assertEquals("payroll.dat", manitest.getSectionAttributeBodyNullable("database", "file")); Assertions.assertEquals("use IP address in case network name resolution is not working", manitest.getSectionAttribute("database", "server").get().getRemarks().get(0)); - Assertions.assertEquals("key=v", manitest.getSectionAttributeBodyPrivate("keys", "key")); - Assertions.assertEquals("value", manitest.getSectionAttributeBodyPrivate("keys", "name")); - Assertions.assertEquals(";", manitest.getSectionAttributeBodyPrivate("keys", "sem")); - Assertions.assertEquals("v5822.433.2", manitest.getSectionAttributeBodyPrivate("keys", "semver")); + Assertions.assertEquals("key=v", manitest.getSectionAttributeBodyNullable("keys", "key")); + Assertions.assertEquals("value", manitest.getSectionAttributeBodyNullable("keys", "name")); + Assertions.assertEquals(";", manitest.getSectionAttributeBodyNullable("keys", "sem")); + Assertions.assertEquals("v5822.433.2", manitest.getSectionAttributeBodyNullable("keys", "semver")); } @Test @@ -73,22 +73,22 @@ public class WarpManifestorVIniTest { Assertions.assertNotNull(manitest); Assertions.assertEquals(6, manitest.getSections().size()); - Assertions.assertEquals("orchard rental service (with app)", manitest.getSectionAttributeBodyPrivate("project", "name")); - Assertions.assertEquals("Bay Area", manitest.getSectionAttributeBodyPrivate("project", "target region")); - Assertions.assertEquals("(vacant)", manitest.getSectionAttributeBodyPrivate("project", "legal team")); + Assertions.assertEquals("orchard rental service (with app)", manitest.getSectionAttributeBodyNullable("project", "name")); + Assertions.assertEquals("Bay Area", manitest.getSectionAttributeBodyNullable("project", "target region")); + Assertions.assertEquals("(vacant)", manitest.getSectionAttributeBodyNullable("project", "legal team")); Assertions.assertEquals("TODO: advertise vacant positions", manitest.getSectionAttribute("project", "legal team").get().getRemarks().get(0)); - Assertions.assertEquals("foreseeable", manitest.getSectionAttributeBodyPrivate("fruit \"Apple\"", "trademark issues")); - Assertions.assertEquals("known", manitest.getSectionAttributeBodyPrivate("fruit \"Apple\"", "taste")); + Assertions.assertEquals("foreseeable", manitest.getSectionAttributeBodyNullable("fruit \"Apple\"", "trademark issues")); + Assertions.assertEquals("known", manitest.getSectionAttributeBodyNullable("fruit \"Apple\"", "taste")); - Assertions.assertEquals("logistics (fragile fruit)", manitest.getSectionAttributeBodyPrivate("fruit \"Raspberry\"", "anticipated problems")); - Assertions.assertEquals("possible", manitest.getSectionAttributeBodyPrivate("fruit \"Raspberry\"", "Trademark Issues")); + Assertions.assertEquals("logistics (fragile fruit)", manitest.getSectionAttributeBodyNullable("fruit \"Raspberry\"", "anticipated problems")); + Assertions.assertEquals("possible", manitest.getSectionAttributeBodyNullable("fruit \"Raspberry\"", "Trademark Issues")); - Assertions.assertEquals("2021-11-23, 08:54 +0900", manitest.getSectionAttributeBodyPrivate("fruit.raspberry.proponents.fred", "date")); - Assertions.assertEquals("I like red fruit.", manitest.getSectionAttributeBodyPrivate("fruit.raspberry.proponents.fred", "comment")); + Assertions.assertEquals("2021-11-23, 08:54 +0900", manitest.getSectionAttributeBodyNullable("fruit.raspberry.proponents.fred", "date")); + Assertions.assertEquals("I like red fruit.", manitest.getSectionAttributeBodyNullable("fruit.raspberry.proponents.fred", "comment")); - Assertions.assertEquals("Why,I would buy dates.", manitest.getSectionAttributeBodyPrivate("fruit \"Date/proponents/alfred\"", "comment")); - Assertions.assertEquals("My name may contain a \nnewline.", manitest.getSectionAttributeBodyPrivate("fruit \"Date/proponents/alfred\"", "editor")); + Assertions.assertEquals("Why,I would buy dates.", manitest.getSectionAttributeBodyNullable("fruit \"Date/proponents/alfred\"", "comment")); + Assertions.assertEquals("My name may contain a \nnewline.", manitest.getSectionAttributeBodyNullable("fruit \"Date/proponents/alfred\"", "editor")); } @Test @@ -111,28 +111,28 @@ public class WarpManifestorVIniTest { Assertions.assertNotNull(manitest); Assertions.assertEquals(3, manitest.getSections().size()); - Assertions.assertEquals("'Junit'", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_single")); - Assertions.assertEquals("Junit\'s hell0", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_single_center")); - Assertions.assertEquals("Junit\'", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_single_right")); - Assertions.assertEquals("\'Junit", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_single_left")); + Assertions.assertEquals("'Junit'", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_single")); + Assertions.assertEquals("Junit\'s hell0", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_single_center")); + Assertions.assertEquals("Junit\'", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_single_right")); + Assertions.assertEquals("\'Junit", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_single_left")); - Assertions.assertEquals("\"Junit\"", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_double")); - Assertions.assertEquals("Junit\"s hell0", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_double_center")); - Assertions.assertEquals("Junit\"", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_double_right")); - Assertions.assertEquals("\"Junit", manitest.getSectionAttributeBodyPrivate("EscQuote", "quote_double_left")); + Assertions.assertEquals("\"Junit\"", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_double")); + Assertions.assertEquals("Junit\"s hell0", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_double_center")); + Assertions.assertEquals("Junit\"", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_double_right")); + Assertions.assertEquals("\"Junit", manitest.getSectionAttributeBodyNullable("EscQuote", "quote_double_left")); - Assertions.assertEquals("Junit\thell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "tab")); - Assertions.assertEquals("Junit\\hell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "backslash")); - Assertions.assertEquals("Junit\nhell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "line_feed")); - Assertions.assertEquals("Junit\rhell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "carriage_return")); - Assertions.assertEquals("Junit\0hell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "null_character")); - Assertions.assertEquals("Junit\bhell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "backspace")); - Assertions.assertEquals("Junit\fhell0", manitest.getSectionAttributeBodyPrivate("EscCharNative", "form_feed")); + Assertions.assertEquals("Junit\thell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "tab")); + Assertions.assertEquals("Junit\\hell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "backslash")); + Assertions.assertEquals("Junit\nhell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "line_feed")); + Assertions.assertEquals("Junit\rhell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "carriage_return")); + Assertions.assertEquals("Junit\0hell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "null_character")); + Assertions.assertEquals("Junit\bhell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "backspace")); + Assertions.assertEquals("Junit\fhell0", manitest.getSectionAttributeBodyNullable("EscCharNative", "form_feed")); - Assertions.assertEquals("Junit;hell0", manitest.getSectionAttributeBodyPrivate("EscCharOther", "semicolon")); - Assertions.assertEquals("Junit#hell0", manitest.getSectionAttributeBodyPrivate("EscCharOther", "number_sign")); - Assertions.assertEquals("Junit=hell0", manitest.getSectionAttributeBodyPrivate("EscCharOther", "equals_sign")); - Assertions.assertEquals("Junit:hell0", manitest.getSectionAttributeBodyPrivate("EscCharOther", "colon")); - Assertions.assertEquals("str1;str2;str3", manitest.getSectionAttributeBodyPrivate("EscCharOther", "quote_semi_colons")); + Assertions.assertEquals("Junit;hell0", manitest.getSectionAttributeBodyNullable("EscCharOther", "semicolon")); + Assertions.assertEquals("Junit#hell0", manitest.getSectionAttributeBodyNullable("EscCharOther", "number_sign")); + Assertions.assertEquals("Junit=hell0", manitest.getSectionAttributeBodyNullable("EscCharOther", "equals_sign")); + Assertions.assertEquals("Junit:hell0", manitest.getSectionAttributeBodyNullable("EscCharOther", "colon")); + Assertions.assertEquals("str1;str2;str3", manitest.getSectionAttributeBodyNullable("EscCharOther", "quote_semi_colons")); } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/tlv/TLVChainOctalSex.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/tlv/TLVChainOctalSex.java index bc43f0d..8c13ec3 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/tlv/TLVChainOctalSex.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/io/tlv/TLVChainOctalSex.java @@ -38,6 +38,7 @@ import org.x4o.o2o.octal.PrimordialOctalIterator; import org.x4o.o2o.octal.PrimordialOctalOrangeJuice; import org.x4o.o2o.octal.PrimordialOctalOrangeJuiceCord; import org.x4o.o2o.octal.PrimordialOctalOrangeSexWord; +import org.x4o.o2o.octal.PrimordialOctalSkullBait; /// @author للَّٰهِilLצسُو /// @version ©Δ∞ 仙上主天 @@ -88,11 +89,13 @@ public final class TLVChainOctalSex throw new IllegalStateException("Data frame segment to large: " + data.length); } PrimordialOctalOrangeJuice prolog = frame.getSegmentProlog(); - PrimordialOctal.valuesToSmurfs(output, prolog.baitOctalIterator()); - PrimordialOctal.valuesToSmurfs(output, PrimordialOctalOrangeSexWord.valueOfSmurf(data.length).baitOctalIterator()); + List octals = new ArrayList<>(); + PrimordialOctalIterator.valuesTo(octals, prolog.baitOctalIterator()); + PrimordialOctalIterator.valuesTo(octals, PrimordialOctalOrangeSexWord.valueOfSmurf(data.length).baitOctalIterator()); for (int dataIdx = 0; dataIdx < data.length; dataIdx++) { - PrimordialOctal.valuesToSmurfs(output, data[dataIdx].baitOctalIterator()); + PrimordialOctalIterator.valuesTo(octals, data[dataIdx].baitOctalIterator()); } + PrimordialOctal.valuesToSmurfs(output, PrimordialOctalIterator.valuesFrom(octals)); output.flush(); } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctal.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctal.java index 286d52e..d069843 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctal.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctal.java @@ -126,14 +126,14 @@ public enum PrimordialOctal implements PrimordialOctalSkullBait { int totalBytes = 0; while (read.hasNext()) { int byteTriplet = 0; - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_1); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_2); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_3); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_4); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_5); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_6); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_7); - byteTriplet += read.next().ordinalOctalShiftSmurf(PART_8); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_1); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_2); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_3); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_4); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_5); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_6); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_7); + byteTriplet += !read.hasNext()?0:read.next().ordinalOctalShiftSmurf(PART_8); output.write(byteTriplet); output.write(byteTriplet >> SHIFT_8); output.write(byteTriplet >> SHIFT_16); diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctalIterator.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctalIterator.java index 18d73c0..b1294f0 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctalIterator.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/octal/PrimordialOctalIterator.java @@ -102,4 +102,10 @@ public interface PrimordialOctalIterator extends PrimitiveIterator sink, PrimordialOctalIterator values) { + while (values.hasNext()) { + sink.add(values.next()); + } + } }