Java Code Examples for org.apache.flink.formats.avro.utils.DataOutputEncoder#setOut()
The following examples show how to use
org.apache.flink.formats.avro.utils.DataOutputEncoder#setOut() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncoderDecoderTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testComplexStringsDirecty() { try { Random rnd = new Random(349712539451944123L); for (int i = 0; i < 10; i++) { String testString = StringUtils.getRandomString(rnd, 10, 100); ByteArrayOutputStream baos = new ByteArrayOutputStream(512); { DataOutputStream dataOut = new DataOutputStream(baos); DataOutputEncoder encoder = new DataOutputEncoder(); encoder.setOut(dataOut); encoder.writeString(testString); dataOut.flush(); dataOut.close(); } byte[] data = baos.toByteArray(); // deserialize { ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream dataIn = new DataInputStream(bais); DataInputDecoder decoder = new DataInputDecoder(); decoder.setIn(dataIn); String deserialized = decoder.readString(); assertEquals(testString, deserialized); } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test failed due to an exception: " + e.getMessage()); } }
Example 2
Source File: EncoderDecoderTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testComplexStringsDirecty() { try { Random rnd = new Random(349712539451944123L); for (int i = 0; i < 10; i++) { String testString = StringUtils.getRandomString(rnd, 10, 100); ByteArrayOutputStream baos = new ByteArrayOutputStream(512); { DataOutputStream dataOut = new DataOutputStream(baos); DataOutputEncoder encoder = new DataOutputEncoder(); encoder.setOut(dataOut); encoder.writeString(testString); dataOut.flush(); dataOut.close(); } byte[] data = baos.toByteArray(); // deserialize { ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream dataIn = new DataInputStream(bais); DataInputDecoder decoder = new DataInputDecoder(); decoder.setIn(dataIn); String deserialized = decoder.readString(); assertEquals(testString, deserialized); } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test failed due to an exception: " + e.getMessage()); } }
Example 3
Source File: EncoderDecoderTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testComplexStringsDirecty() { try { Random rnd = new Random(349712539451944123L); for (int i = 0; i < 10; i++) { String testString = StringUtils.getRandomString(rnd, 10, 100); ByteArrayOutputStream baos = new ByteArrayOutputStream(512); { DataOutputStream dataOut = new DataOutputStream(baos); DataOutputEncoder encoder = new DataOutputEncoder(); encoder.setOut(dataOut); encoder.writeString(testString); dataOut.flush(); dataOut.close(); } byte[] data = baos.toByteArray(); // deserialize { ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream dataIn = new DataInputStream(bais); DataInputDecoder decoder = new DataInputDecoder(); decoder.setIn(dataIn); String deserialized = decoder.readString(); assertEquals(testString, deserialized); } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Test failed due to an exception: " + e.getMessage()); } }