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.EncodeHintType;
22 import com.google.zxing.common.BitMatrix;
23 import org.hedgecode.chess.img.ImageFormat;
24 import org.hedgecode.chess.qrcode.ChessQRCodeException;
25 import org.hedgecode.chess.qrcode.ChessQRCodeMode;
26 import org.hedgecode.chess.qrcode.ChessQRCodeWriter;
31 * @author Dmitry Samoshin aka gotty
33 public class ZipChessQRCodeWriter extends ChessQRCodeWriter {
35 private static ChessQRCodeWriter _instance = new ZipChessQRCodeWriter();
37 protected ZipChessQRCodeWriter() {
42 protected BitMatrix encode(
45 int width, int height,
46 Map<EncodeHintType,?> hints)
47 throws ChessQRCodeException
49 if (mode == null || mode.isArchive()) {
50 throw new ChessQRCodeException(
51 ChessQRCodeException.Type.WRITE, "write.qrcode.mode.null"
55 if (contents == null || contents.isEmpty()) {
56 throw new ChessQRCodeException(
57 ChessQRCodeException.Type.WRITE, "write.qrcode.contents.empty"
61 String zipContents = ZipContentDeflater.deflate(
62 mode.name().concat(contents)
66 ChessQRCodeMode.ZIP, zipContents, width, height, hints
70 public static ChessQRCodeWriter getInstance() {
75 public static void main(String[] args) {
77 ZipChessQRCodeWriter.getInstance().write(
79 "1.e4 c6 2.d4 d5 3.Nc3 dxe4 4.Nxe4 Nd7 5.Ng5 Ngf6 6.Bd3 e6 7.N1f3 h6\n" +
80 "8.Nxe6 Qe7 9.O-O fxe6 10.Bg6+ Kd8 {Каспаров встряхнул головой} \n" +
81 "11.Bf4 b5 12.a4 Bb7 13.Re1 Nd5 14.Bg3 Kc8 15.axb5 cxb5 16.Qd3 Bc6 \n" +
82 "17.Bf5 exf5 18.Rxe7 Bxe7 19.c4 1-0",
86 } catch (ChessQRCodeException e) {
87 System.out.println("Could not generate QR Code, Exception: " + e.getMessage());