当前位置: 首页>>代码示例>>Java>>正文


Java GZIPInputStream类代码示例

本文整理汇总了Java中java.util.zip.GZIPInputStream的典型用法代码示例。如果您正苦于以下问题:Java GZIPInputStream类的具体用法?Java GZIPInputStream怎么用?Java GZIPInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GZIPInputStream类属于java.util.zip包,在下文中一共展示了GZIPInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getReader

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
/**
 * This method checks if the given file is a Zip file containing one entry (in case of file
 * extension .zip). If this is the case, a reader based on a ZipInputStream for this entry is
 * returned. Otherwise, this method checks if the file has the extension .gz. If this applies, a
 * gzipped stream reader is returned. Otherwise, this method just returns a BufferedReader for
 * the given file (file was not zipped at all).
 */
public static BufferedReader getReader(File file, Charset encoding) throws IOException {
	// handle zip files if necessary
	if (file.getAbsolutePath().endsWith(".zip")) {
		try (ZipFile zipFile = new ZipFile(file)) {
			if (zipFile.size() == 0) {
				throw new IOException("Input of Zip file failed: the file archive does not contain any entries.");
			}
			if (zipFile.size() > 1) {
				throw new IOException("Input of Zip file failed: the file archive contains more than one entry.");
			}
			Enumeration<? extends ZipEntry> entries = zipFile.entries();
			InputStream zipIn = zipFile.getInputStream(entries.nextElement());
			return new BufferedReader(new InputStreamReader(zipIn, encoding));
		}
	} else if (file.getAbsolutePath().endsWith(".gz")) {
		return new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), encoding));
	} else {
		return new BufferedReader(new InputStreamReader(new FileInputStream(file), encoding));
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:28,代码来源:Tools.java

示例2: isInputStreamGZIPCompressed

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
/**
 * Checks the InputStream if it contains  GZIP compressed data
 *
 * @param inputStream InputStream to be checked
 * @return true or false if the stream contains GZIP compressed data
 * @throws java.io.IOException if read from inputStream fails
 */
public static boolean isInputStreamGZIPCompressed(final PushbackInputStream inputStream) throws IOException {
    if (inputStream == null)
        return false;

    byte[] signature = new byte[2];
    int count = 0;
    try {
        while (count < 2) {
            int readCount = inputStream.read(signature, count, 2 - count);
            if (readCount < 0) return false;
            count = count + readCount;
        }
    } finally {
        inputStream.unread(signature, 0, count);
    }
    int streamHeader = ((int) signature[0] & 0xff) | ((signature[1] << 8) & 0xff00);
    return GZIPInputStream.GZIP_MAGIC == streamHeader;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:AsyncHttpClient.java

示例3: init

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
static void init() {
	try {
		glossary = new Vector();
		URL url = URLFactory.url( DSDP.ROOT+"fauna/glossary.gz");
		BufferedReader in = new BufferedReader(
			new InputStreamReader( 
			new GZIPInputStream( url.openStream() )));
		String s;
		while( (s=in.readLine())!=null ) glossary.add(s.getBytes());
		glossary.trimToSize();
	} catch(IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:15,代码来源:FossilGlossary.java

示例4: createInput

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
static public InputStream createInput(File file) {
    if (file == null) {
        throw new IllegalArgumentException("File passed to createInput() was null");
    }
    try {
        InputStream input = new FileInputStream(file);
        if (file.getName().toLowerCase().endsWith(".gz")) {
            return new GZIPInputStream(input);
        }
        return input;

    } catch (IOException e) {
        System.err.println("Could not createInput() for " + file);
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:18,代码来源:FileIO.java

示例5: read

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
public static void read(File file, Consumer<File> handle) throws IOException {
    Path temp;
    if (SystemUtils.IS_OS_LINUX) {
        temp = Files.createTempFile(SHARED_MEMORY, TEMP_PREFIX, null);
    } else {
        temp = Files.createTempFile(TEMP_PREFIX, null);
    }

    try (
            InputStream is = new FileInputStream(file);
            GZIPInputStream gis = new GZIPInputStream(is);
            OutputStream os = Files.newOutputStream(temp);
    ) {
        byte[] buffer = new byte[1024];
        int length;
        while ((length = gis.read(buffer, 0, 1024)) != -1) {
            os.write(buffer, 0, length);
        }

        handle.accept(temp.toFile());
    } finally {
        Files.delete(temp);
    }
}
 
开发者ID:sip3io,项目名称:tapir,代码行数:25,代码来源:GzipFileReader.java

示例6: getGameFileFromFile

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
private static GameFile getGameFileFromFile(String file) throws JAXBException, IOException {
  final JAXBContext jaxbContext = JAXBContext.newInstance(GameFile.class);
  final Unmarshaller um = jaxbContext.createUnmarshaller();
  try (InputStream inputStream = FileUtilities.getGameResource(file)) {

    // try to get compressed game file
    final GZIPInputStream zipStream = new GZIPInputStream(inputStream);
    return (GameFile) um.unmarshal(zipStream);
  } catch (final ZipException e) {

    // if it fails to load the compressed file, get it from plain XML
    InputStream stream = null;
    stream = FileUtilities.getGameResource(file);
    if (stream == null) {
      return null;
    }

    return (GameFile) um.unmarshal(stream);
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:21,代码来源:GameFile.java

示例7: loadHexFiles

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
private void loadHexFiles() throws FileNotFoundException, IOException
{
    FilenameFilter filter = new UniverseFilter("hex");
    File directory = new File("data");
    File[] files = directory.listFiles(filter);
    for (File file : files)
    {
        FileInputStream fos = new FileInputStream(file); // Save to file
        GZIPInputStream gzos = new GZIPInputStream(fos);
        DataInputStream data = new DataInputStream(gzos);
        int count = data.readInt();
        List<Coord> newMap = new LinkedList<Coord>();
        for (int i = 0; i < count; i++)
        {
            newMap.add(new Coord(data.readInt(), data.readInt(), data.readInt()));
            data.readInt();
        }
        data.close(); // Close the stream.
        _log.info(newMap.size() + " map vertices loaded from file " + file.getName());
        _coordList.addAll(newMap);
    }
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:23,代码来源:Universe.java

示例8: loadBinFiles

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
@SuppressWarnings(value = {"unchecked"})
private void loadBinFiles() throws FileNotFoundException, IOException, ClassNotFoundException
{
    FilenameFilter filter = new UniverseFilter("bin");
    File directory = new File("data");
    File[] files = directory.listFiles(filter);
    for (File file : files)
    {
        //Create necessary input streams
        FileInputStream fis = new FileInputStream(file); // Read from file
        GZIPInputStream gzis = new GZIPInputStream(fis); // Uncompress
        ObjectInputStream in = new ObjectInputStream(gzis); // Read objects
        // Read in an object. It should be a vector of scribbles

        TreeSet<Position> temp = (TreeSet<Position>) in.readObject();
        _log.info(temp.size() + " map vertices loaded from file " + file.getName());
        in.close(); // Close the stream.
        for (Position p : temp)
        {
            _coordList.add(new Coord(p._x, p._y, p._z));
        }
    }
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:24,代码来源:Universe.java

示例9: StatArchiveFile

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
public StatArchiveFile(StatArchiveReader reader, File archiveName, boolean dump,
    ValueFilter[] filters) throws IOException {
  this.reader = reader;
  this.archiveName = archiveName;
  this.dump = dump;
  this.compressed = archiveName.getPath().endsWith(".gz");
  this.is = new FileInputStream(this.archiveName);
  if (this.compressed) {
    this.dataIn = new DataInputStream(
        new BufferedInputStream(new GZIPInputStream(this.is, BUFFER_SIZE), BUFFER_SIZE));
  } else {
    this.dataIn = new DataInputStream(new BufferedInputStream(this.is, BUFFER_SIZE));
  }
  this.updateOK = this.dataIn.markSupported();
  this.filters = createFilters(filters);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:StatArchiveReader.java

示例10: readCompressedFile

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
public String readCompressedFile(String fileName) {
    try {
        GZIPInputStream gis = new GZIPInputStream(new FileInputStream(fileName));
        ByteArrayOutputStream fos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = gis.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
        }
        fos.close();
        gis.close();
        return new String(fos.toByteArray());
    } catch (IOException ex) {
        System.out.println("Invalid input file!");
        return null;
    }
}
 
开发者ID:mhdehghan,项目名称:SamanGar,代码行数:18,代码来源:ReadData.java

示例11: gzipUncompressToString

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
public static String gzipUncompressToString(byte[] b) {
    if (b == null || b.length == 0) {
        return null;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayInputStream in = new ByteArrayInputStream(b);
    try {
        GZIPInputStream gunzip = new GZIPInputStream(in);
        byte[] buffer = new byte[256];
        int n;
        while ((n = gunzip.read(buffer)) >= 0) {
            out.write(buffer, 0, n);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toString();
}
 
开发者ID:zh-h,项目名称:pxclawer,代码行数:19,代码来源:StringUtil.java

示例12: init

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
static void init() {
	try {
		glossary = new Vector();
		URL url = URLFactory.url( DSDP.ROOT+"authors.list.gz");
		BufferedReader in = new BufferedReader(
			new InputStreamReader(
			new GZIPInputStream( url.openStream() )));
		String s = in.readLine();
		while( (s=in.readLine())!=null ) glossary.add(s.getBytes());
		glossary.trimToSize();
	} catch(IOException e) {
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:14,代码来源:AuthorGlossary.java

示例13: getReader

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
/**
 * Creates a BufferedReader for the given input path Can handle both gzip
 * and plain text files
 * 
 * @param file
 * @return
 * @throws IOException
 */
public static BufferedReader getReader(File file) throws IOException {
    if (!file.exists()) {
        throw new IOException("The file '" + file + "' does not exist");
    }

    BufferedReader in = null;
    if (file.getPath().endsWith(".gz")) {
        FileInputStream fin = new FileInputStream(file);
        GZIPInputStream gzis = new GZIPInputStream(fin);
        in = new BufferedReader(new InputStreamReader(gzis));
        LOG.debug("Reading in the zipped contents of '" + file.getName() + "'");
    } else {
        in = new BufferedReader(new FileReader(file));
        LOG.debug("Reading in the contents of '" + file.getName() + "'");
    }
    return (in);
}
 
开发者ID:faclc4,项目名称:HTAPBench,代码行数:26,代码来源:FileUtil.java

示例14: download

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
private void download(String urlString, LocalDate localDate) throws IOException {
    URL url = new URL(urlString);
    try (InputStream is = url.openStream();
         GZIPInputStream gzis = new GZIPInputStream(is);
         InputStreamReader isr = new InputStreamReader(gzis, StandardCharsets.UTF_8);
         BufferedReader br = new BufferedReader(isr)) {
        List<InfoSchema> infos = new ArrayList<>();
        String line;
        while ((line = br.readLine()) != null) {
            if (!line.isEmpty()) {
                InfoSchema info = parseLineToInfo(line, localDate);
                if (info != null) {
                    infos.add(info);
                }
            }
        }

        this.databaseService.saveInfos(infos);
    }
}
 
开发者ID:CrazyBBB,项目名称:tenhou-visualizer,代码行数:21,代码来源:DownloadService.java

示例15: testGzipDurability

import java.util.zip.GZIPInputStream; //导入依赖的package包/类
@Test
public void testGzipDurability() throws Exception {
  Context context = new Context();
  HDFSCompressedDataStream writer = new HDFSCompressedDataStream();
  writer.configure(context);
  writer.open(fileURI, factory.getCodec(new Path(fileURI)),
      SequenceFile.CompressionType.BLOCK);

  String[] bodies = { "yarf!" };
  writeBodies(writer, bodies);

  byte[] buf = new byte[256];
  GZIPInputStream cmpIn = new GZIPInputStream(new FileInputStream(file));
  int len = cmpIn.read(buf);
  String result = new String(buf, 0, len, Charsets.UTF_8);
  result = result.trim(); // BodyTextEventSerializer adds a newline

  Assert.assertEquals("input and output must match", bodies[0], result);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:20,代码来源:TestHDFSCompressedDataStream.java


注:本文中的java.util.zip.GZIPInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。