summaryrefslogtreecommitdiffstats
path: root/src/org/uic/ticket/api/UicRailTicketCoder.java
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2020-07-28 17:56:59 +0200
committerCGantert345 <57003061+CGantert345@users.noreply.github.com>2020-07-28 17:56:59 +0200
commitaaeb77f8f58ebc01fd241139439a8d290765e5fc (patch)
tree4ce4a7300af0360d16e35156cde8a164779dd96a /src/org/uic/ticket/api/UicRailTicketCoder.java
parentbugfix activated day (diff)
downloadUIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.tar
UIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.tar.gz
UIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.tar.bz2
UIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.tar.lz
UIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.tar.xz
UIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.tar.zst
UIC-barcode-aaeb77f8f58ebc01fd241139439a8d290765e5fc.zip
Diffstat (limited to '')
-rw-r--r--src/org/uic/ticket/UicRailTicketCoder.java (renamed from src/org/uic/ticket/api/UicRailTicketCoder.java)82
1 files changed, 58 insertions, 24 deletions
diff --git a/src/org/uic/ticket/api/UicRailTicketCoder.java b/src/org/uic/ticket/UicRailTicketCoder.java
index 0221526..82a546f 100644
--- a/src/org/uic/ticket/api/UicRailTicketCoder.java
+++ b/src/org/uic/ticket/UicRailTicketCoder.java
@@ -1,16 +1,18 @@
/*
*
*/
-package org.uic.ticket.api;
+package org.uic.ticket;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.uic.ticket.api.asn.omv1.UicRailTicketData;
+
import org.uic.ticket.api.spec.IUicRailTicket;
import org.uic.ticket.api.utils.Api2OpenAsnEncoder;
+import org.uic.ticket.api.utils.Api2OpenAsnEncoderV2;
import org.uic.ticket.api.utils.OpenAsn2ApiDecoder;
+import org.uic.ticket.api.utils.OpenAsn2ApiDecoderV2;
/**
@@ -69,16 +71,25 @@ public class UicRailTicketCoder {
* @throws EncodingFormatException signals that a format rule of the asn.1 specification was violated.
*/
public byte[] encode (IUicRailTicket uicRailTicket, int version) throws IOException, EncodingFormatException{
+
+
+ if (version == 1) {
+
+ Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
+
+ return uicEncoder.encode(uicRailTicket);
+
+
+ } else if (version == 2) {
+
+ Api2OpenAsnEncoderV2 uicEncoder = new Api2OpenAsnEncoderV2();
+
+ return uicEncoder.encode(uicRailTicket);
- if (version != 1) {
- throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
}
- Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
-
- UicRailTicketData asnUicRailTicketData = uicEncoder.populateToAsn1Model(uicRailTicket);
-
- return asnUicRailTicketData.encode();
+ throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
+
}
@@ -94,17 +105,32 @@ public class UicRailTicketCoder {
*/
public void encode ( ByteArrayOutputStream outputStream, IUicRailTicket uicRailTicket, int version) throws IOException, EncodingFormatException{
- if (version != 1) {
- throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
- }
+
- Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
+ if (version == 1) {
- UicRailTicketData asnUicRailTicketData = uicEncoder.populateToAsn1Model(uicRailTicket);
+ Api2OpenAsnEncoder uicEncoder = new Api2OpenAsnEncoder();
- outputStream.write(asnUicRailTicketData.encode());
+ org.uic.ticket.api.asn.omv1.UicRailTicketData asnUicRailTicketData = uicEncoder.populateToAsn1Model(uicRailTicket);
- return;
+ outputStream.write(asnUicRailTicketData.encode());
+
+ return;
+
+
+ } else if (version == 2) {
+
+ Api2OpenAsnEncoderV2 uicEncoder = new Api2OpenAsnEncoderV2();
+
+ org.uic.ticket.api.asn.omv2.UicRailTicketData asnUicRailTicketData = uicEncoder.populateToAsn1Model(uicRailTicket);
+
+ outputStream.write(asnUicRailTicketData.encode());
+
+ return;
+
+ }
+
+ throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
}
@@ -118,17 +144,25 @@ public class UicRailTicketCoder {
*/
public IUicRailTicket decodeFromAsn (byte[] byteData, int version) throws IOException, EncodingFormatException{
- if (version != 1) {
- throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
- }
-
- UicRailTicketData asnUicRailTicketData = UicRailTicketData.decode(byteData);
+ if (version == 1) {
+
+ OpenAsn2ApiDecoder uicDecoder = new OpenAsn2ApiDecoder();
+
+ IUicRailTicket uicRailTicket = uicDecoder.decodeFromAsn(byteData);
+
+ return uicRailTicket;
- OpenAsn2ApiDecoder uicDecoder = new OpenAsn2ApiDecoder();
+ } else if (version == 2) {
- IUicRailTicket uicRailTicket = uicDecoder.decodeFromAsn(asnUicRailTicketData);
+ OpenAsn2ApiDecoderV2 uicDecoder = new OpenAsn2ApiDecoderV2();
+
+ IUicRailTicket uicRailTicket = uicDecoder.decodeFromAsn(byteData);
+
+ return uicRailTicket;
+
+ }
- return uicRailTicket;
+ throw new EncodingFormatException(String.format("Encoding version %d not supported", version));
}