1/* Copyright 2015 Google Inc. All Rights Reserved. 2 3 Distributed under MIT license. 4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5*/ 6 7package org.brotli.dec; 8 9/** 10 * A set of utility methods. 11 */ 12final class Utils { 13 14 private static final byte[] BYTE_ZEROES = new byte[1024]; 15 16 private static final int[] INT_ZEROES = new int[1024]; 17 18 /** 19 * Fills byte array with zeroes. 20 * 21 * <p> Current implementation uses {@link System#arraycopy}, so it should be used for length not 22 * less than 16. 23 * 24 * @param dest array to fill with zeroes 25 * @param offset the first byte to fill 26 * @param length number of bytes to change 27 */ 28 static void fillWithZeroes(byte[] dest, int offset, int length) { 29 int cursor = 0; 30 while (cursor < length) { 31 int step = Math.min(cursor + 1024, length) - cursor; 32 System.arraycopy(BYTE_ZEROES, 0, dest, offset + cursor, step); 33 cursor += step; 34 } 35 } 36 37 /** 38 * Fills int array with zeroes. 39 * 40 * <p> Current implementation uses {@link System#arraycopy}, so it should be used for length not 41 * less than 16. 42 * 43 * @param dest array to fill with zeroes 44 * @param offset the first item to fill 45 * @param length number of item to change 46 */ 47 static void fillWithZeroes(int[] dest, int offset, int length) { 48 int cursor = 0; 49 while (cursor < length) { 50 int step = Math.min(cursor + 1024, length) - cursor; 51 System.arraycopy(INT_ZEROES, 0, dest, offset + cursor, step); 52 cursor += step; 53 } 54 } 55} 56