Tabnine Logo
org.h2.compress
Code IndexAdd Tabnine to your IDE (free)

How to use org.h2.compress

Best Java code snippets using org.h2.compress (Showing top 20 results out of 315)

origin: com.h2database/h2

private static Compressor getCompressor(boolean fast) {
  return fast ? new CompressLZF() : new CompressDeflate();
}
origin: com.h2database/h2

Compressor getCompressorFast() {
  if (compressorFast == null) {
    compressorFast = new CompressLZF();
  }
  return compressorFast;
}
origin: com.h2database/h2

public LZFOutputStream(OutputStream out) throws IOException {
  this.out = out;
  int len = Constants.IO_BUFFER_SIZE_COMPRESS;
  buffer = new byte[len];
  ensureOutput(len);
  writeInt(MAGIC);
}
origin: com.h2database/h2

private void fillBuffer() throws IOException {
  if (buffer != null && pos < bufferLength) {
    return;
  }
  int len = readInt();
  if (decompress == null) {
    // EOF
    this.bufferLength = 0;
  } else if (len < 0) {
    len = -len;
    buffer = ensureSize(buffer, len);
    readFully(buffer, len);
    this.bufferLength = len;
  } else {
    inBuffer = ensureSize(inBuffer, len);
    int size = readInt();
    readFully(inBuffer, len);
    buffer = ensureSize(buffer, size);
    try {
      decompress.expand(inBuffer, 0, len, buffer, 0, size);
    } catch (ArrayIndexOutOfBoundsException e) {
      DbException.convertToIOException(e);
    }
    this.bufferLength = size;
  }
  pos = 0;
}
origin: com.h2database/h2

private static Compressor getCompressor(int algorithm) {
  switch (algorithm) {
  case Compressor.NO:
    return new CompressNo();
  case Compressor.LZF:
    return new CompressLZF();
  case Compressor.DEFLATE:
    return new CompressDeflate();
  default:
    throw DbException.get(
        ErrorCode.UNSUPPORTED_COMPRESSION_ALGORITHM_1,
        "" + algorithm);
  }
}
origin: com.h2database/h2

private void compressAndWrite(byte[] buff, int len) throws IOException {
  if (len > 0) {
    ensureOutput(len);
    int compressed = compress.compress(buff, len, outBuffer, 0);
    if (compressed > len) {
      writeInt(-len);
      out.write(buff, 0, len);
    } else {
      writeInt(compressed);
      writeInt(len);
      out.write(outBuffer, 0, compressed);
    }
  }
}
origin: com.h2database/h2

private static int compress(byte[] in, int len, Compressor compress,
    byte[] out) {
  int newLen = 0;
  out[0] = (byte) compress.getAlgorithm();
  int start = 1 + writeVariableInt(out, 1, len);
  newLen = compress.compress(in, len, out, start);
  if (newLen > len + start || newLen <= 0) {
    out[0] = Compressor.NO;
    System.arraycopy(in, 0, out, start, len);
    newLen = len + start;
  }
  return newLen;
}
origin: com.h2database/h2

Compressor getCompressorHigh() {
  if (compressorHigh == null) {
    compressorHigh = new CompressDeflate();
  }
  return compressorHigh;
}
origin: com.h2database/h2

@Override
public int read() throws IOException {
  fillBuffer();
  if (pos >= bufferLength) {
    return -1;
  }
  return buffer[pos++] & 255;
}
origin: com.h2database/h2

@Override
public void write(int b) throws IOException {
  if (pos >= buffer.length) {
    flush();
  }
  buffer[pos++] = (byte) b;
}
origin: com.h2database/h2

@Override
public void flush() throws IOException {
  compressAndWrite(buffer, pos);
  pos = 0;
}
origin: com.h2database/h2

@Override
public int read(byte[] b) throws IOException {
  return read(b, 0, b.length);
}
origin: com.h2database/h2

@Override
public int read(byte[] b, int off, int len) throws IOException {
  if (len == 0) {
    return 0;
  }
  int read = 0;
  while (len > 0) {
    int r = readBlock(b, off, len);
    if (r < 0) {
      break;
    }
    read += r;
    off += r;
    len -= r;
  }
  return read == 0 ? -1 : read;
}
origin: com.h2database/h2

public LZFInputStream(InputStream in) throws IOException {
  this.in = in;
  if (readInt() != LZFOutputStream.MAGIC) {
    throw new IOException("Not an LZFInputStream");
  }
}
origin: com.h2database/h2

private byte[] expand(int page) {
  byte[] d = getPage(page);
  if (d.length == BLOCK_SIZE) {
    return d;
  }
  byte[] out = new byte[BLOCK_SIZE];
  if (d != COMPRESSED_EMPTY_BLOCK) {
    synchronized (LZF) {
      LZF.expand(d, 0, d.length, out, 0, BLOCK_SIZE);
    }
  }
  setPage(page, d, out, false);
  return out;
}
origin: com.h2database/h2

@Override
public int compress(byte[] in, int inLen, byte[] out, int outPos) {
  Deflater deflater = new Deflater(level);
  deflater.setStrategy(strategy);
  deflater.setInput(in, 0, inLen);
  deflater.finish();
  int compressed = deflater.deflate(out, outPos, out.length - outPos);
  while (compressed == 0) {
    // the compressed length is 0, meaning compression didn't work
    // (sounds like a JDK bug)
    // try again, using the default strategy and compression level
    strategy = Deflater.DEFAULT_STRATEGY;
    level = Deflater.DEFAULT_COMPRESSION;
    return compress(in, inLen, out, outPos);
  }
  deflater.end();
  return outPos + compressed;
}
origin: com.h2database/h2

  @Override
  protected CompressLZF initialValue() {
    return new CompressLZF();
  }
};
origin: com.h2database/h2

private int readBlock(byte[] b, int off, int len) throws IOException {
  fillBuffer();
  if (pos >= bufferLength) {
    return -1;
  }
  int max = Math.min(len, bufferLength - pos);
  max = Math.min(max, b.length - off);
  System.arraycopy(buffer, pos, b, off, max);
  pos += max;
  return max;
}
origin: com.h2database/h2

@Override
public void close() throws IOException {
  flush();
  out.close();
}
origin: com.h2database/h2

PageLog(PageStore store) {
  this.store = store;
  dataBuffer = store.createData();
  trace = store.getTrace();
  compress = new CompressLZF();
  compressBuffer = new byte[store.getPageSize() * 2];
}
org.h2.compress

Most used classes

  • CompressDeflate
    This is a wrapper class for the Deflater class. This algorithm supports the following options: * l o
  • CompressLZF
    This class implements the LZF lossless data compression algorithm. LZF is a Lempel-Ziv variant with
  • Compressor
    Each data compression algorithm must implement this interface.
  • CompressNo
    This class implements a data compression algorithm that does in fact not compress. This is useful if
  • LZFInputStream
    An input stream to read from an LZF stream. The data is automatically expanded.
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now