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;
19 import java.util.Arrays;
20 import java.util.Base64;
25 * @author Dmitry Samoshin aka gotty
27 public class ZipContentUtils {
29 private static final int LENGTH_BYTE_COUNT = 4;
31 private static final int MAX_CONTENT_LENGTH = 65536;
33 public static int getMaxContentLength() {
34 return MAX_CONTENT_LENGTH;
37 public static int getZipLength(byte[] zipBytes) {
39 Arrays.copyOf(zipBytes, LENGTH_BYTE_COUNT)
43 public static byte[] getZipBytes(byte[] zipBytes) {
44 return Arrays.copyOfRange(
45 zipBytes, LENGTH_BYTE_COUNT, zipBytes.length
49 public static byte[] concat(int length, byte[] bytes) {
56 public static String base64Encode(byte[] bytes) {
57 return Base64.getEncoder().encodeToString(bytes);
60 public static byte[] base64Decode(String value) {
61 return Base64.getDecoder().decode(value);
64 private static byte[] toByteArray(int value) {
73 private static int fromByteArray(byte[] bytes) {
75 | (bytes[1] & 0xFF) << 16
76 | (bytes[2] & 0xFF) << 8
80 private static byte[] concat(byte[]... byteArrays) {
82 for (byte[] bytes : byteArrays) {
83 length += bytes.length;
85 byte[] concatBytes = new byte[length];
87 for (byte[] bytes : byteArrays) {
88 if (bytes.length == 0)
90 System.arraycopy(bytes, 0, concatBytes, length, bytes.length);
91 length += bytes.length;
96 private ZipContentUtils() {
97 throw new AssertionError(
98 "No org.hedgecode.chess.qrcode.zip.ZipContentUtils instances!"