本文整理汇总了Java中org.xerial.snappy.SnappyOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java SnappyOutputStream类的具体用法?Java SnappyOutputStream怎么用?Java SnappyOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SnappyOutputStream类属于org.xerial.snappy包,在下文中一共展示了SnappyOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
@Override
public void process(Document document) throws IOException {
ByteArrayOutputStream array = new ByteArrayOutputStream();
ObjectOutputStream output;
if (compressed) {
output = new ObjectOutputStream(new SnappyOutputStream(array));
} else {
output = new ObjectOutputStream(array);
}
output.writeObject(document);
output.close();
byte[] key = Utility.fromLong(document.identifier);
byte[] value = array.toByteArray();
KeyValuePair pair = new KeyValuePair(key, value);
processor.process(pair);
}
示例2: toBytes
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
@Override
public byte[] toBytes(Document doc) throws IOException {
ByteArrayOutputStream headerArray = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(headerArray);
// identifier
output.writeLong(doc.identifier);
// name
SerializerCommon.writeString(output, doc.name);
ByteArrayOutputStream metadataArray = SerializerCommon.writeMetadata(doc);
ByteArrayOutputStream textArray = SerializerCommon.writeText(doc);
ByteArrayOutputStream docArray = new ByteArrayOutputStream();
output = new DataOutputStream(new SnappyOutputStream(docArray));
output.writeInt(metadataArray.size());
output.writeInt(textArray.size());
output.write(headerArray.toByteArray());
output.write(metadataArray.toByteArray());
output.write(textArray.toByteArray());
output.close();
return docArray.toByteArray();
}
示例3: getStream
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
private static Stuff getStream(final String name) throws IOException {
Stuff s = m_files.get(name);
if (s == null) {
File f = new VoltFile(path, name);
f.delete();
RandomAccessFile ras = new RandomAccessFile(f, "rw");
ras.seek(8);
SnappyOutputStream sos = new SnappyOutputStream(new FileOutputStream(ras.getFD()));
DataOutputStream dos = new DataOutputStream(sos);
s = new Stuff();
s.dos = dos;
s.count = ras.getChannel().map(MapMode.READ_WRITE, 0, 8);
s.count.order(ByteOrder.nativeOrder());
m_files.put(name, s);
}
return s;
}
示例4: getConpressedOutputStream
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
public static DataOutputStream getConpressedOutputStream(MessageCompressionType type, OutputStream outputStream) throws IOException {
switch (type) {
case NONE:
return new DataOutputStream(outputStream);
case SNAPPY:
return new DataOutputStream(new SnappyOutputStream(outputStream));
case GZIP:
try {
return new DataOutputStream(new GZIPOutputStream(outputStream));
} catch (IOException e) {
LOG.error("Create Gzip OuputStream failed", e);
throw e;
}
default:
throw new RuntimeException("Unsupported Compression type: " + type);
}
}
示例5: openDictionary
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
public void openDictionary(String dir, String prefix, long unique_prefix)
throws FileNotFoundException, IOException {
String filename = prefix + "-";
NumberFormat f = NumberFormat.getInstance();
f.setMinimumIntegerDigits(5);
f.setGroupingUsed(false);
filename += f.format(unique_prefix);
File fDir = new File(dir);
if (!fDir.exists() || !fDir.isDirectory()) {
fDir.mkdirs();
}
// Write the URIs in a file in the output dir
stream = new DataOutputStream(new SnappyOutputStream(
new FileOutputStream(new File(dir, filename))));
}
示例6: serializeToByteArray
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
/**
* Serializes the argument into an array of bytes, and returns it.
*
* @throws IllegalArgumentException if there are errors when serializing
*/
public static byte[] serializeToByteArray(Serializable value) {
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(new SnappyOutputStream(buffer))) {
oos.writeObject(value);
}
return buffer.toByteArray();
} catch (IOException exn) {
throw new IllegalArgumentException(
"unable to serialize " + value,
exn);
}
}
示例7: toBytes
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
@Override
public byte[] toBytes(Document doc) throws IOException {
ByteArrayOutputStream headerArray = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(headerArray);
// identifier
output.writeLong(doc.identifier);
// name
byte[] bytes = ByteUtil.fromString(doc.name);
output.writeInt(bytes.length);
output.write(bytes);
output.close();
ByteArrayOutputStream metadataArray = SerializerCommon.writeMetadata(doc);
ByteArrayOutputStream textArray = SerializerCommon.writeText(doc);
ByteArrayOutputStream termsArray = SerializerCommon.writeTerms(doc);
ByteArrayOutputStream docArray = new ByteArrayOutputStream();
output = new DataOutputStream(new SnappyOutputStream(docArray));
output.write(headerArray.toByteArray());
output.writeInt(metadataArray.size());
output.writeInt(textArray.size());
output.writeInt(termsArray.size());
output.write(metadataArray.toByteArray());
output.write(textArray.toByteArray());
output.write(termsArray.toByteArray());
output.close();
return docArray.toByteArray();
}
示例8: save
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
@Override
public void save(String saveFileName) throws IOException {
Kryo kryo = CubeUtils.getKryoWithRegistrations();
OutputStream zip = new SnappyOutputStream(new FileOutputStream(saveFileName));
Output output = new Output(zip);
kryo.writeClassAndObject(output, partitions);
// zip.closeEntry();
output.close();
// zip.close();
}
示例9: compress
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
@Override
public void compress(InputStream source, OutputStream target) {
Validate.notNull(source);
Validate.notNull(target);
try (OutputStream os = new SnappyOutputStream(target)) {
IOUtils.copy(source, os);
}
catch (IOException e) {
throw new IllegalStateException(e);
} finally {
IOUtils.closeQuietly(source);
}
}
示例10: compactar
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
public static String compactar(String path) throws IOException {
String compressed = path + ".cpt";
FileOutputStream fos = new FileOutputStream(compressed);
SnappyOutputStream sout = new SnappyOutputStream(fos);
FileInputStream fis = new FileInputStream(path);
BufferedInputStream input = new BufferedInputStream(fis);
ByteArrayOutputStream orig = new ByteArrayOutputStream();
byte[] tmp = new byte[1024];
for (int readBytes = 0; (readBytes = input.read(tmp)) != -1;) {
sout.write(tmp, 0, readBytes);
orig.write(tmp, 0, readBytes);
}
input.close();
sout.flush();
sout.close();
orig.flush();
orig.close();
fos.flush();
fos.close();
return compressed;
}
示例11: create
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
public static OutputStream create(final CompressionCodec compressionCodec, final OutputStream stream) throws IOException {
switch (compressionCodec) {
case NONE:
return stream;
case GZIP:
return new GZIPOutputStream(stream);
case SNAPPY:
return new SnappyOutputStream(stream);
case LZ4:
// TODO Implement KafkaLZ4BlockOutputStream
//return new KafkaLZ4BlockOutputStream(stream);
default:
throw new UnknownCodecException("Unknown Codec: " + compressionCodec);
}
}
示例12: apply
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
public static OutputStream apply(CompressionCodec compressionCodec, OutputStream stream) {
try {
if (compressionCodec == DefaultCompressionCodec.instance) return new GZIPOutputStream(stream);
if (compressionCodec == GZIPCompressionCodec.instance) return new GZIPOutputStream(stream);
if (compressionCodec == SnappyCompressionCodec.instance) return new SnappyOutputStream(stream);
} catch (IOException e) {
throw new KafkaException(e);
}
throw new kafka.common.UnknownCodecException("Unknown Codec: " + compressionCodec);
}
示例13: createSnappyInputStream
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
private SnappyInputStream createSnappyInputStream() throws IOException {
// Create an in-memory ZIP output stream for use by the input stream (to avoid exceptions)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SnappyOutputStream sos = new SnappyOutputStream( baos );
byte[] testBytes = "Test".getBytes();
sos.write( testBytes );
ByteArrayInputStream in = new ByteArrayInputStream( baos.toByteArray() );
sos.close();
return new SnappyInputStream( in );
}
示例14: wrapOut
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
@Override
@Nonnull
public OutputStream wrapOut(@Nonnull OutputStream out, int option) throws IOException {
return option == -1 ? new SnappyOutputStream(out) : new SnappyOutputStream(out, option);
}
示例15: SnappyCompression
import org.xerial.snappy.SnappyOutputStream; //导入依赖的package包/类
public SnappyCompression(InputStream inputStream, OutputStream outputStream) throws IOException {
super(inputStream != null ? new SnappyInputStream(inputStream) : null, //
outputStream != null ? new SnappyOutputStream(outputStream) : null);
}