2 * Copyright (c) 2018-2019. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.qrcode.zip;
21 import com.google.zxing.common.DecoderResult;
23 import org.hedgecode.chess.qrcode.ChessQRCodeException;
24 import org.hedgecode.chess.qrcode.ChessQRCodeMode;
25 import org.hedgecode.chess.qrcode.ChessQRCodeReader;
26 import org.hedgecode.chess.qrcode.ChessQRResult;
31 * @author Dmitry Samoshin aka gotty
33 public class ZipChessQRCodeReader extends ChessQRCodeReader {
35 private static ZipChessQRCodeReader _instance = new ZipChessQRCodeReader();
37 protected ZipChessQRCodeReader() {
42 protected ChessQRResult createResult(DecoderResult decoderResult) throws ChessQRCodeException {
43 String result = decoderResult.getText();
44 ChessQRCodeMode mode = ChessQRResult.getMode(result);
46 if (ChessQRCodeMode.ZIP.equals(mode)) {
47 String contents = ZipContentInflater.inflate(
48 ChessQRResult.getContents(result)
51 mode = ChessQRResult.getMode(contents);
53 throw new ChessQRCodeException(
54 ChessQRCodeException.Type.READ, "read.unknown.chess.mode"
58 return new ChessQRResult(
60 ChessQRResult.getContents(contents)
63 return super.createResult(decoderResult);
67 public static ZipChessQRCodeReader getInstance() {
72 public static void main(String[] args) {
74 ChessQRResult qrCodeResult = ZipChessQRCodeReader.getInstance().read(
75 new File("qrcode.png")
77 System.out.println("Decoded format = " + qrCodeResult.getMode());
78 System.out.println("Decoded text = " + qrCodeResult.getContents());
79 } catch (ChessQRCodeException e) {
80 System.out.println("Could not decode QR Code. Exception: " + e.getMessage());