protected void checkPrefixCodec(PrefixCodec codec, Random r) throws IOException { int[] symbol = new int[100]; BooleanArrayList bits = new BooleanArrayList(); for (int i = 0; i < symbol.length; i++) symbol[i] = r.nextInt(codec.size()); for (int i = 0; i < symbol.length; i++) { BitVector word = codec.codeWords()[symbol[i]]; for (int j = 0; j < word.size(); j++) bits.add(word.get(j)); } BooleanIterator booleanIterator = bits.iterator(); Decoder decoder = codec.decoder(); for (int i = 0; i < symbol.length; i++) { assertEquals(decoder.decode(booleanIterator), symbol[i]); } FastByteArrayOutputStream fbaos = new FastByteArrayOutputStream(); OutputBitStream obs = new OutputBitStream(fbaos, 0); obs.write(bits.iterator()); obs.flush(); InputBitStream ibs = new InputBitStream(fbaos.array); for (int i = 0; i < symbol.length; i++) { assertEquals(decoder.decode(ibs), symbol[i]); } }
public void testDecodeUint64() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream( new byte[] { (byte) 0x00, (byte) 0xff, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xab, (byte) 0xcd, (byte) 0xef, (byte) 0xff, (byte) 0xfe, (byte) 0xdc, (byte) 0xba, (byte) 0x98, (byte) 0x76, (byte) 0x54, (byte) 0x32, (byte) 0x10 }); final long[] expected = new long[] {0L, 0x0123456789abcdefL, 0xfedcba9876543210L}; Decoder d = new Decoder(input); for (long u64 : expected) { assertEquals(u64, d.uint64()); } }
public Result decode(BinaryBitmap image, Hashtable hints) throws NotFoundException, ChecksumException, FormatException { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.getBlackMatrix()); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.getBlackMatrix()).detect(); decoderResult = decoder.decode(detectorResult.getBits()); points = detectorResult.getPoints(); } Result result = new Result( decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.DATAMATRIX); if (decoderResult.getByteSegments() != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.getByteSegments()); } if (decoderResult.getECLevel() != null) { result.putMetadata( ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.getECLevel().toString()); } return result; }
public void testDecodeInt64() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream( new byte[] { (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xfe, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x01 }); final long[] expected = new long[] {0L, 9223372036854775807L, -9223372036854775808L, -1L}; Decoder d = new Decoder(input); for (long s64 : expected) { assertEquals(s64, d.int64()); } }
@Test public void test() { byte[] segment = new byte[20000]; new Random().nextBytes(segment); Decoder decoder = createDecoder(segment.length, 20); Encoder encoder = createEncoder(segment, 0, segment.length, 20); while (!decoder.isDecoded()) { byte[] packet = new byte[20 + segment.length / 20]; encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); } byte[] decodedSegment = new byte[segment.length]; decoder.getSegment(decodedSegment, 0); assertArrayEquals(segment, decodedSegment); }
@Test public void testTooManyPackets() { byte[] segment = new byte[20000]; new Random().nextBytes(segment); Decoder decoder = createDecoder(segment.length, 20); Encoder encoder = createEncoder(segment, 0, segment.length, 20); while (!decoder.isDecoded()) { byte[] packet = new byte[20 + segment.length / 20]; encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); } for (int i = 0; i < 1000; i++) { byte[] packet = new byte[20 + segment.length / 20]; encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); } }
public ResolvedInclude read(Decoder decoder) throws Exception { String include = decoder.readString(); File included = null; if (decoder.readBoolean()) { included = fileSerializer.read(decoder); } return new ResolvedInclude(include, included); }
/** * Test method for {@link Decoder#decodeAROAccretionToARODisc(java.lang.String, * java.lang.String)}. */ @Test public void testDecodeAROAccretionToARODisc() { String s = "ARO_ACCRETION1"; assertEquals("ARO_DISC1", Decoder.decodeAROAccretionToARODisc(s)); s = "ARO_ACCRETION2"; assertEquals("ARO_DISC2", Decoder.decodeAROAccretionToARODisc(s)); }
/** * Test method for {@link Decoder#decodeDiscAROtoUndiscARO(java.lang.String, java.lang.String)}. */ @Test public void testDecodeDiscAROtoUndiscARO() { String s = "ARO_DISC1"; assertEquals("ARO_UNDISC1", Decoder.decodeDiscAROtoUndiscARO(s)); s = "ARO_DISC2"; assertEquals("ARO_UNDISC2", Decoder.decodeDiscAROtoUndiscARO(s)); }
public void decode(Decoder decoder) { super.decode(decoder); int2 = decoder.decodeInt(); string2 = decoder.decodeString(); int length = decoder.decodeInt(); buffer2 = decoder.decodeKnownLengthBuffer(length, true); }
public void testDecodeObject() throws IOException { final byte[] stubObjectTypeIDBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; class DummyObject implements BinaryObject { final String dummy = "dummy"; @Override public ObjectTypeID type() { return new ObjectTypeID(stubObjectTypeIDBytes); } @Override public void decode(@NotNull Decoder d) throws IOException { assert d.string().equals(dummy); } @Override public void encode(@NotNull Encoder e) throws IOException { e.string(dummy); } } final BinaryObject dummyObject = new DummyObject(); class DummyObjectCreator implements BinaryObjectCreator { @Override public BinaryObject create() { return dummyObject; } } final BinaryObjectCreator dummyObjectCreator = new DummyObjectCreator(); ObjectTypeID.register(dummyObject.type(), dummyObjectCreator); ByteArrayOutputStream inputBytes = new ByteArrayOutputStream(); // null BinaryObject: inputBytes.write(new byte[] {(byte) 0x00}); // BinaryObject.NULL_ID // stubObject: inputBytes.write(new byte[] {0x01}); // stubObject reference inputBytes.write(stubObjectTypeIDBytes); // stubObject.type() inputBytes.write(new byte[] {0x05, 'd', 'u', 'm', 'm', 'y'}); // stubObject again, only by reference this time: inputBytes.write(new byte[] {0x01}); // stubObject reference final ByteArrayInputStream input = new ByteArrayInputStream(inputBytes.toByteArray()); final BinaryObject[] expected = new BinaryObject[] {null, dummyObject, dummyObject}; Decoder d = new Decoder(input); for (BinaryObject obj : expected) { assertEquals(obj, d.object()); } }
public void testDecodeBool() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {(byte) 0x01, (byte) 0x00}); final boolean[] expected = new boolean[] {true, false}; Decoder d = new Decoder(input); for (boolean bool : expected) { assertEquals(bool, d.bool()); } }
public void testDecodeUint8() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {(byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xff}); final short[] expected = new short[] {0x00, 0x7f, 0x80, 0xff}; Decoder d = new Decoder(input); for (short u8 : expected) { assertEquals(u8, d.uint8() & 0xff); } }
public void testDecodeInt8() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream(new byte[] {(byte) 0x00, (byte) 0x7f, (byte) 0x80, (byte) 0xff}); final byte[] expected = new byte[] {0, 127, -128, -1}; Decoder d = new Decoder(input); for (short s8 : expected) { assertEquals(s8, d.int8()); } }
/** Test method for {@link Decoder#decodeReplace(java.lang.String, java.lang.String)}. */ @Test public void testDecodeReplace() { String memberName = "ARO_ACCRETION1"; String pattern = "ACCRETION"; String replacement = "DISC"; assertEquals("ARO_DISC1", Decoder.decodeReplace(memberName, pattern, replacement)); memberName = "ARO_DISC1"; pattern = "DISC"; replacement = "UNDISC"; assertEquals("ARO_UNDISC1", Decoder.decodeReplace(memberName, pattern, replacement)); }
@Override public void run() { while (!decoder.complete()) { decoder.run(); decoder.pushPacket(new Packet(ppl.receive())); } ppl.complete(); try { decoder.dump(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Decoder complete : " + decoder.received + " packets received."); }
/** Test method for {@link Decoder#decodeIntToYear(java.lang.String, java.lang.String)}. */ @Test public void testDecodeIntToYear() { int i = 2011; assertEquals("FY11", Decoder.decodeIntToYear(i)); i = 112; assertEquals("FY12", Decoder.decodeIntToYear(i)); i = 13; assertEquals("FY13", Decoder.decodeIntToYear(i)); i = 4; assertEquals("FY04", Decoder.decodeIntToYear(i)); }
@Override public boolean process( final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) { System.out.println(roundEnv); System.out.println(annotations); for (Element elem : roundEnv.getElementsAnnotatedWith(Decoder.class)) { Decoder decoder = elem.getAnnotation(Decoder.class); String message = String.format( "Annotation found in %s with decoder %s.", elem.getSimpleName(), decoder.value()); processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, message); } return true; }
public void testDecodeString() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream( new byte[] { 0x05, 'H', 'e', 'l', 'l', 'o', 0x00, // empty string 0x05, 'W', 'o', 'r', 'l', 'd', 0x15, (byte) 0xe3, (byte) 0x81, (byte) 0x93, (byte) 0xe3, (byte) 0x82, (byte) 0x93, (byte) 0xe3, (byte) 0x81, (byte) 0xab, (byte) 0xe3, (byte) 0x81, (byte) 0xa1, (byte) 0xe3, (byte) 0x81, (byte) 0xaf, (byte) 0xe4, (byte) 0xb8, (byte) 0x96, (byte) 0xe7, (byte) 0x95, (byte) 0x8c }); final String[] expected = new String[] {"Hello", "", "World", "こんにちは世界"}; Decoder d = new Decoder(input); for (String str : expected) { assertEquals(str, d.string()); } }
@Test public void testDecodeWithData() throws IOException { JacksonJsonSupport jsonSupport = new JacksonJsonSupport(new Configuration()); jsonSupport.addEventMapping("edwald", HashMap.class, Integer.class, String.class); Decoder decoder = new Decoder(jsonSupport, ackManager); Packet packet = decoder.decodePacket("5:::{\"name\":\"edwald\",\"args\":[{\"a\": \"b\"},2,\"3\"]}", null); Assert.assertEquals(PacketType.EVENT, packet.getType()); Assert.assertEquals("edwald", packet.getName()); Assert.assertEquals(3, packet.getArgs().size()); Map obj = (Map) packet.getArgs().get(0); Assert.assertEquals("b", obj.get("a")); Assert.assertEquals(2, packet.getArgs().get(1)); Assert.assertEquals("3", packet.getArgs().get(2)); }
void doProtocolInitialisation(int dx, int dy) throws IOException { rfb.writeClientInit(); rfb.readServerInit(); initializeBitmap(dx, dy); decoder.setPixelFormat(rfb); }
/** * Broken tests atm: 00035: I don't even... 00036: broken: unicode string that is actually * encodable as latin1 00085: long unicode string that contains only latin1, so we can't * roundtrip... * * @param args * @throws IOException * @throws SerealException */ public static void main(String[] args) throws IOException { String manual = null; // "../test_dir/test_data_00029"; if (args.length == 0 && manual == null) { throw new UnsupportedOperationException("Usage: Example [test_dir OR test_data_00XXXX]"); } final File target = new File((manual == null ? args[0] : manual)).getCanonicalFile(); // to absorb ".." in paths if (!target.exists()) { throw new FileNotFoundException("No such file or directory: " + target.getAbsolutePath()); } if (target.isDirectory()) { System.out.println("Running decoder on all test files in " + target.getCanonicalPath()); decodeAllTests(target); } else { verbose = true; System.out.println("Decoding a single file: " + target.getAbsolutePath()); // more logging dec.debugTrace = true; enc.debugTrace = true; roundtrip(target); } }
public void decode(Decoder decoder) { int1 = decoder.decodeInt(); float1 = decoder.decodeFloat(); long1 = decoder.decodeLong(); boolean1 = decoder.decodeBoolean(); string1 = decoder.decodeString(); date1 = decoder.decodeDate(); bytes1 = decoder.decodeBytes(); codable1 = decoder.decodeCodable(); }
@Test public void testLinearDependance() { byte[] segment = new byte[1000]; new Random().nextBytes(segment); Decoder decoder = createDecoder(segment.length, 10); byte[] packet = new byte[10 + segment.length / 10]; Encoder encoder = createEncoder(segment, 0, segment.length, 10); encoder.getPacket(packet, 0); decoder.addPacket(packet, 0); decoder.addPacket(packet, 0); assertEquals(1, decoder.getRank()); while (!decoder.isDecoded()) { byte[] packet2 = new byte[10 + segment.length / 10]; encoder.getPacket(packet2, 0); decoder.addPacket(packet2, 0); } byte[] decodedSegment = new byte[segment.length]; decoder.getSegment(decodedSegment, 0); assertArrayEquals(segment, decodedSegment); }
@Test public void testGB() { byte[] segment = new byte[22500]; new Random().nextBytes(segment); byte[][] packets = new byte[25][25 + 900]; long startTime = System.currentTimeMillis(); Encoder encoder = createEncoder(segment, 0, segment.length, 25); for (int i = 0; i < 1000; i++) { for (int j = 0; j < 25; j++) { encoder.getPacket(packets[j], 0); } } System.out.println( "Rate:" + (8 * 1000.0 * segment.length) / (double) (System.currentTimeMillis() - startTime) + " kbps"); startTime = System.currentTimeMillis(); for (int i = 0; i < 1000; i++) { Decoder decoder = createDecoder(segment.length, 25); for (int j = 0; j < 25; j++) { decoder.addPacket(packets[j], 0); } byte[] decodedSegment = new byte[segment.length]; decoder.getSegment(decodedSegment, 0); } System.out.println( "Rate:" + (8 * 1000.0 * segment.length) / (double) (System.currentTimeMillis() - startTime) + " kbps"); }
public void testDecodeUint16() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream( new byte[] { (byte) 0x00, (byte) 0xc0, (byte) 0xbe, (byte) 0xef, (byte) 0xc0, (byte) 0xc0, (byte) 0xde }); final int[] expected = new int[] {0, 0xbeef, 0xc0de}; Decoder d = new Decoder(input); for (int u16 : expected) { assertEquals(u16, d.uint16() & 0xffff); } }
public void testDecodeFloat32() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream( new byte[] { (byte) 0x00, (byte) 0xc0, (byte) 0x80, (byte) 0x3f, (byte) 0xc0, (byte) 0x81, (byte) 0x42, }); final float[] expected = new float[] {0.F, 1.F, 64.5F}; Decoder d = new Decoder(input); for (float f32 : expected) { assertEquals(f32, d.float32()); } }
/** * Decode the Base64-encoded data in input and return the data in a new byte array. * * <p>The padding '=' characters at the end are considered optional, but if any are present, there * must be the correct number of them. * * @param input the data to decode * @param offset the position within the input array at which to start * @param len the number of bytes of input to decode * @param flags controls certain features of the decoded output. Pass {@code DEFAULT} to decode * standard Base64. * @throws IllegalArgumentException if the input contains incorrect padding */ public static byte[] decode(byte[] input, int offset, int len, int flags) { // Allocate space for the most data the input could represent. // (It could contain less if it contains whitespace, etc.) Decoder decoder = new Decoder(flags, new byte[len * 3 / 4]); if (!decoder.process(input, offset, len, true)) { throw new IllegalArgumentException("bad base-64"); } // Maybe we got lucky and allocated exactly enough output space. if (decoder.op == decoder.output.length) { return decoder.output; } // Need to shorten the array, so allocate a new one of the // right size and copy. byte[] temp = new byte[decoder.op]; System.arraycopy(decoder.output, 0, temp, 0, decoder.op); return temp; }
public void testDecodeInt16() throws IOException { final ByteArrayInputStream input = new ByteArrayInputStream( new byte[] { (byte) 0x00, (byte) 0xc0, (byte) 0xff, (byte) 0xfe, (byte) 0xc0, (byte) 0xff, (byte) 0xff, (byte) 0x01, }); final short[] expected = new short[] {0, 32767, -32768, -1}; Decoder d = new Decoder(input); for (short s16 : expected) { assertEquals(s16, d.int16()); } }
public CompilationState read(Decoder decoder) throws Exception { CompilationState compilationState = new CompilationState(); int version = decoder.readInt(); if (version != SERIAL_VERSION) { return compilationState; } compilationState.sourceInputs.addAll(fileListSerializer.read(decoder)); compilationState.fileStates.putAll(stateMapSerializer.read(decoder)); return compilationState; }