private void changeLength(long len) { length = len; len = MathUtils.roundUpLong(len, BLOCK_SIZE); int blocks = (int) (len >>> BLOCK_SIZE_SHIFT); if (blocks != data.length) { ByteBuffer[] n = new ByteBuffer[blocks]; System.arraycopy(data, 0, n, 0, Math.min(data.length, n.length)); for (int i = data.length; i < blocks; i++) { n[i] = COMPRESSED_EMPTY_BLOCK; } data = n; } }
private void changeLength(long len) { length = len; len = MathUtils.roundUpLong(len, BLOCK_SIZE); int blocks = (int) (len >>> BLOCK_SIZE_SHIFT); if (blocks != data.length) { byte[][] n = new byte[blocks][]; System.arraycopy(data, 0, n, 0, Math.min(data.length, n.length)); for (int i = data.length; i < blocks; i++) { n[i] = COMPRESSED_EMPTY_BLOCK; } data = n; } }
private static int getBufferSize(DataHandler handler, boolean compress, long remaining) { if (remaining < 0 || remaining > Integer.MAX_VALUE) { remaining = Integer.MAX_VALUE; } int inplace = handler.getMaxLengthInplaceLob(); long m = compress ? Constants.IO_BUFFER_SIZE_COMPRESS : Constants.IO_BUFFER_SIZE; if (m < remaining && m <= inplace) { // using "1L" to force long arithmetic because // inplace could be Integer.MAX_VALUE m = Math.min(remaining, inplace + 1L); // the buffer size must be bigger than the inplace lob, otherwise we // can't know if it must be stored in-place or not m = MathUtils.roundUpLong(m, Constants.IO_BUFFER_SIZE); } m = Math.min(remaining, m); m = MathUtils.convertLongToInt(m); if (m < 0) { m = Integer.MAX_VALUE; } return (int) m; }
/** * Truncate the file. * * @param newLength the new length */ void truncate(long newLength) { changeLength(newLength); long end = MathUtils.roundUpLong(newLength, BLOCK_SIZE); if (end != newLength) { int lastPage = (int) (newLength >>> BLOCK_SIZE_SHIFT); expand(data, lastPage); ByteBuffer d = data[lastPage]; for (int i = (int) (newLength & BLOCK_SIZE_MASK); i < BLOCK_SIZE; i++) { d.put(i, (byte) 0); } if (compress) { compressLater(data, lastPage); } } }
/** * Truncate the file. * * @param newLength the new length */ void truncate(long newLength) { changeLength(newLength); long end = MathUtils.roundUpLong(newLength, BLOCK_SIZE); if (end != newLength) { int lastPage = (int) (newLength >>> BLOCK_SIZE_SHIFT); expand(data, lastPage); byte[] d = data[lastPage]; for (int i = (int) (newLength & BLOCK_SIZE_MASK); i < BLOCK_SIZE; i++) { d[i] = 0; } if (compress) { compressLater(data, lastPage); } } }