|
Lucene example source code file (StreamUtils.java)
The Lucene StreamUtils.java source codepackage org.apache.lucene.benchmark.byTask.utils; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.compress.compressors.CompressorStreamFactory; /** * Stream utilities. */ public class StreamUtils { /** Buffer size used across the benchmark package */ public static final int BUFFER_SIZE = 1 << 16; // 64K /** File format type */ public enum Type { /** BZIP2 is automatically used for <b>.bz2 and .bzip2 extensions. */ BZIP2(CompressorStreamFactory.BZIP2), /** GZIP is automatically used for <b>.gz and .gzip extensions. */ GZIP(CompressorStreamFactory.GZIP), /** Plain text is used for anything which is not GZIP or BZIP. */ PLAIN(null); private final String csfType; Type(String csfType) { this.csfType = csfType; } private InputStream inputStream(InputStream in) throws IOException { try { return csfType==null ? in : closableCompressorInputStream(this, in); } catch (CompressorException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } } private OutputStream outputStream(OutputStream os) throws IOException { try { return csfType==null ? os : new CompressorStreamFactory().createCompressorOutputStream(csfType, os); } catch (CompressorException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } } } private static final Map<String,Type> extensionToType = new HashMap Other Lucene examples (source code examples)Here is a short list of links related to this Lucene StreamUtils.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.