java.util.zip.GZIPInputStream Java Examples

The following examples show how to use java.util.zip.GZIPInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LyU.java    From cocos-ui-libgdx with Apache License 2.0 7 votes vote down vote up
public static byte[] unGzip(byte[] encode) {
    ByteArrayInputStream bais = new ByteArrayInputStream(encode);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] result = null;
    try {
        GZIPInputStream gis = new GZIPInputStream(bais);
        int count;
        byte data[] = new byte[1024];
        while ((count = gis.read(data, 0, 1024)) != -1) {
            baos.write(data, 0, count);
        }
        gis.close();
        result = baos.toByteArray();
        baos.flush();
        baos.close();
        bais.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
Example #2
Source File: Man2HtmlTest.java    From Man-Man with GNU General Public License v3.0 7 votes vote down vote up
@Test
public void testHtmlOutput() throws IOException {
    //FileInputStream fis = new FileInputStream("/usr/share/man/man1/systemctl.1.gz");
    //FileInputStream fis = new FileInputStream("/usr/share/man/man1/tar.1.gz");
    //FileInputStream fis = new FileInputStream("/usr/share/man/man8/sudo.8.gz");
    FileInputStream fis = new FileInputStream("/usr/share/man/man1/grep.1.gz");
    GZIPInputStream gis = new GZIPInputStream(fis);
    BufferedReader br = new BufferedReader(new InputStreamReader(gis));
    Man2Html m2h = new Man2Html(br);
    String result = m2h.getHtml();
    br.close();

    String homeDir = System.getProperty("user.home");
    FileOutputStream fos = new FileOutputStream(homeDir + File.separator + "test.html");
    OutputStreamWriter osw = new OutputStreamWriter(fos);
    osw.write(result);
    osw.close();

    Runtime.getRuntime().exec("xdg-open " + homeDir + File.separator + "test.html");
}
 
Example #3
Source File: ExtendedAccumuloBlobStoreTest.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSaveAndQueryComplex() throws Exception {
    ExtendedAccumuloBlobStore blobStore = new ExtendedAccumuloBlobStore(getConnector(), CHUNK_SIZE);

    Collection<String> testValues = new ArrayList<String>(10);
    for (int i = 0; i < CHUNK_SIZE; i++)
        testValues.add(randomUUID().toString());

    //Store json in a Gzipped format
    OutputStream storageStream = blobStore.store("test", "1", currentTimeMillis(), "");
    mapper.writeValue(new GZIPOutputStream(storageStream), testValues);

    //reassemble the json after unzipping the stream.
    InputStream retrievalStream = blobStore.get("test", "1", Auths.EMPTY);
    Collection<String> actualValues = mapper.readValue(new GZIPInputStream(retrievalStream), strColRef);

    //if there were no errors, then verify that the two collections are equal.
    assertThat(actualValues, is(equalTo(testValues)));
}
 
Example #4
Source File: GZFile.java    From bistoury with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 主方法
 */
public static void main(String[] args) throws Exception {
    File file = new File("D:\\localhost.2018-10-31.log.gz");
    InputStream stream = new BufferedInputStream(new FileInputStream(file));
    if (isGZipFile(stream)) {
        GZIPInputStream ungzip = new GZIPInputStream(stream);
        InputStream inputStream = ungzip;
        OutputStream fos = new FileOutputStream("D:\\1.txt");
        byte[] b = new byte[1024];
        while (inputStream.read(b, 0, 1024) != -1) {
            fos.write(b, 0, 1024);
        }
        fos.flush();
    } else if (isGZipFile(stream)) {

    }
}
 
Example #5
Source File: GZIPUtils.java    From beihu-boot with Apache License 2.0 6 votes vote down vote up
/**
 * @param bytes
 * @param encoding
 * @return
 */
public static String uncompressToString(byte[] bytes, String encoding) {
    if (bytes == null || bytes.length == 0) {
        return null;
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    try {
        GZIPInputStream ungzip = new GZIPInputStream(in);
        byte[] buffer = new byte[256];
        int n;
        while ((n = ungzip.read(buffer)) >= 0) {
            out.write(buffer, 0, n);
        }
        return out.toString(encoding);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
Example #6
Source File: HttpDataPointProtobufReceiverConnectionTest.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
                   HttpServletResponse response) throws IOException, ServletException {
    if (!request.getHeader("X-SF-TOKEN").equals(AUTH_TOKEN)) {
        error("Invalid auth token", response, baseRequest);
        return;
    }
    if (!request.getHeader("User-Agent")
            .equals(AbstractHttpReceiverConnection.USER_AGENT)) {
        error("Invalid User agent: " + request.getHeader("User-Agent") + " vs "
                + AbstractHttpReceiverConnection.USER_AGENT, response, baseRequest);
        return;
    }
    SignalFxProtocolBuffers.DataPointUploadMessage all_datapoints =
            SignalFxProtocolBuffers.DataPointUploadMessage.parseFrom(
                    new GZIPInputStream(baseRequest.getInputStream()));
    if (!all_datapoints.getDatapoints(0).getSource().equals("source")) {
        error("Invalid datapoint source", response, baseRequest);
        return;
    }
    response.setStatus(HttpStatus.SC_OK);
    response.getWriter().write("\"OK\"");
    baseRequest.setHandled(true);
}
 
Example #7
Source File: FileUtils.java    From SVG-Android with Apache License 2.0 6 votes vote down vote up
public static void unZipGzipFile(File source, File destination) throws IOException {
    if (destination.getParentFile().exists() || destination.getParentFile().mkdirs()) {
        FileInputStream fis = new FileInputStream(source);
        FileOutputStream fos = new FileOutputStream(destination);
        GZIPInputStream gis = new GZIPInputStream(fis);
        int count;
        byte[] data = new byte[1024];
        while ((count = gis.read(data, 0, 1024)) != -1) {
            fos.write(data, 0, count);
        }
        gis.close();
        fis.close();
        fos.flush();
        fos.close();
    }
}
 
Example #8
Source File: SwaggerBasePathRewritingFilterTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void run_on_valid_response_gzip() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/service1" + DEFAULT_URL);
    RequestContext context = RequestContext.getCurrentContext();
    context.setRequest(request);

    MockHttpServletResponse response = new MockHttpServletResponse();
    context.setResponseGZipped(true);
    context.setResponse(response);

    context.setResponseDataStream(new ByteArrayInputStream(gzipData("{\"basePath\":\"/\"}")));

    filter.run();

    assertEquals("UTF-8", response.getCharacterEncoding());

    InputStream responseDataStream = new GZIPInputStream(context.getResponseDataStream());
    String responseBody = IOUtils.toString(responseDataStream, StandardCharsets.UTF_8);
    assertEquals("{\"basePath\":\"/service1\"}", responseBody);
}
 
Example #9
Source File: ResourceSyncFileLoader.java    From timbuctoo with GNU General Public License v3.0 6 votes vote down vote up
public static InputStream maybeDecompress(InputStream input) throws IOException {
  final PushbackInputStream pb = new PushbackInputStream(input, 2);

  int header = pb.read();
  if (header == -1) {
    return pb;
  }

  int firstByte = pb.read();
  if (firstByte == -1) {
    pb.unread(header);
    return pb;
  }

  pb.unread(new byte[]{(byte) header, (byte) firstByte});

  header = (firstByte << 8) | header;

  if (header == GZIPInputStream.GZIP_MAGIC) {
    return new GZIPInputStream(pb);
  } else {
    return pb;
  }
}
 
Example #10
Source File: GZipCompressor.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public ByteBuffer decompress(final InputStream instr) {
	try {
		final GZIPInputStream gzin = new GZIPInputStream(instr);
		final DataInputStream din = new DataInputStream(gzin);
		
		final int length = din.readInt();
		final byte[] xbuf = new byte[length];
		for (int cursor = 0; cursor < length;) {
			final int rdlen = din.read(xbuf, cursor, (length - cursor));
			
			cursor += rdlen;
			
		}
		
		return ByteBuffer.wrap(xbuf);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example #11
Source File: IndexAggregate.java    From cramtools with Apache License 2.0 6 votes vote down vote up
public static IndexAggregate forDataFile(SeekableStream stream, SAMSequenceDictionary dictionary)
		throws IOException {
	String path = stream.getSource();
	File indexFile = findIndexFileFor(path);
	if (indexFile == null)
		throw new FileNotFoundException("No index found for file: " + path);

	log.info("Using index file: " + indexFile.getAbsolutePath());
	IndexAggregate a = new IndexAggregate();
	if (indexFile.getName().matches("(?i).*\\.bai")) {
		a.bai = new CachingBAMFileIndex(indexFile, dictionary);
		return a;
	}
	if (indexFile.getName().matches("(?i).*\\.crai")) {
		a.crai = CramIndex.readIndex(new GZIPInputStream(new FileInputStream(indexFile)));
		return a;
	}

	throw new FileNotFoundException("No index found for file: " + path);
}
 
Example #12
Source File: CompressUtils.java    From jeesuite-libs with Apache License 2.0 6 votes vote down vote up
/**
 * GZIP解压缩
 * 
 * @param bytes
 * @return
 */
public static byte[] gzipUncompress(byte[] bytes) {
	if (bytes == null || bytes.length == 0) {
		return null;
	}
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	ByteArrayInputStream in = new ByteArrayInputStream(bytes);
	try {
		GZIPInputStream ungzip = new GZIPInputStream(in);
		byte[] buffer = new byte[256];
		int n;
		while ((n = ungzip.read(buffer)) >= 0) {
			out.write(buffer, 0, n);
		}
	} catch (IOException e) {
	}

	return out.toByteArray();
}
 
Example #13
Source File: DcResponse.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used to receive a stream of response body.
 * @param res Response object
 * @return Stream
 * @throws IOException Exception thrown
 */
protected final InputStream getResponseBodyInputStream(final HttpResponse res) throws IOException {
    // GZip 圧縮されていたら解凍する。
    /** thaw if it is GZip compression. */
    Header[] contentEncodingHeaders = res.getHeaders("Content-Encoding");
    if (contentEncodingHeaders.length > 0 && "gzip".equalsIgnoreCase(contentEncodingHeaders[0].getValue())) {
        return new GZIPInputStream(res.getEntity().getContent());
    } else {
        HttpEntity he = res.getEntity();
        if (he != null) {
            return he.getContent();
        } else {
            return null;
        }
    }
}
 
Example #14
Source File: ResourceControllerTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testCompression() throws ServletException, IOException {
	// create an empty mock context
	MockServletContext context = new TestServletContext(true);
	MockHttpServletRequest request = new MockHttpServletRequest(context);
	request.addHeader("Accept-Encoding", "gzip");
	request.setPathInfo("/org/geomajas/servlet/test.js");
	request.setMethod("GET");
	MockHttpServletResponse response = new MockHttpServletResponse();
	ResourceController resourceController = new ResourceController();
	resourceController.setServletContext(context);
	resourceController.getResource(request, response);
	Resource resource = new ClassPathResource("/org/geomajas/servlet/test.js");
	GZIPInputStream gzipInputStream = new GZIPInputStream(
			new ByteArrayInputStream(response.getContentAsByteArray()));
	Assert.assertArrayEquals(IOUtils.toByteArray(resource.getInputStream()), IOUtils.toByteArray(gzipInputStream));
}
 
Example #15
Source File: Methods.java    From RP-DBSCAN with Apache License 2.0 6 votes vote down vote up
public AssignCorePointToCluster(Configuration conf, String pairOutputPath) {
	// TODO Auto-generated constructor stub
	this.conf = conf;
	this.pairOutputPath = pairOutputPath;
	FileSystem fs = null;
	try {
	fs = FileSystem.get(this.conf);
	FileStatus[] status = fs.listStatus(new Path(Conf.metaResult));
	BufferedInputStream bi = new BufferedInputStream(fs.open(status[0].getPath()));
	GZIPInputStream gis = new GZIPInputStream(bi);
	ObjectInputStream ois = new ObjectInputStream(gis);
	this.clusters = (List<Cluster>)ois.readObject();
	ois.close();
	gis.close();
	bi.close();

	} catch (IOException | ClassNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example #16
Source File: GzipWriterTest.java    From monsoon with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void writeDirect() throws Exception {
    byte output[] = new byte[data.length];

    try (FileChannel fd = FileChannel.open(file.toPath(), StandardOpenOption.WRITE)) {
        try (FileWriter writer = new GzipWriter(new FileChannelWriter(fd, 0))) {
            ByteBuffer buf = ByteBuffer.allocateDirect(data.length);
            buf.put(data);
            buf.flip();
            while (buf.hasRemaining())
                writer.write(buf);
        }
    }

    try (InputStream input = new GZIPInputStream(new FileInputStream(file))) {
        int off = 0;
        while (off < output.length) {
            int rlen = input.read(output, off, output.length - off);
            assertNotEquals("insufficient bytes were written", -1, rlen);
            off += rlen;
        }
    }

    assertArrayEquals(data, output);
}
 
Example #17
Source File: ZkGrep.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Gunzip a file
 * @param zipFile
 * @return
 */
static File gunzip(File zipFile) {
  File outputFile = new File(stripGzSuffix(zipFile.getAbsolutePath()));

  byte[] buffer = new byte[1024];

  try {

    GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(zipFile));
    FileOutputStream out = new FileOutputStream(outputFile);

    int len;
    while ((len = gzis.read(buffer)) > 0) {
      out.write(buffer, 0, len);
    }

    gzis.close();
    out.close();

    return outputFile;
  } catch (IOException e) {
    LOG.error("fail to gunzip file: " + zipFile, e);
  }

  return null;
}
 
Example #18
Source File: AccumuloBlobStoreTest.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Test
public void testSaveAndQueryComplex() throws Exception {
    AccumuloBlobStore blobStore = new AccumuloBlobStore(getConnector(), CHUNK_SIZE);

    Collection<String> testValues = new ArrayList<String>(10);
    for (int i = 0; i < CHUNK_SIZE; i++)
        testValues.add(randomUUID().toString());

    //Store json in a Gzipped format
    OutputStream storageStream = blobStore.store("test", "1", currentTimeMillis(), "");
    mapper.writeValue(new GZIPOutputStream(storageStream), testValues);

    //reassemble the json after unzipping the stream.
    InputStream retrievalStream = blobStore.get("test", "1", Auths.EMPTY);
    Collection<String> actualValues = mapper.readValue(new GZIPInputStream(retrievalStream), strColRef);

    //if there were no errors, then verify that the two collections are equal.
    assertThat(actualValues, is(equalTo(testValues)));
}
 
Example #19
Source File: MergeLogFiles.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
     * Creates a new <code>Reader</code> that reads from the given log
     * file with the given name.  Invoking this constructor will start
     * this reader thread.
     * @param patterns java regular expressions that an entry must match one or more of
     */
    public NonThreadedReader(InputStream logFile, String logFileName,
                  ThreadGroup group, boolean tabOut, boolean suppressBlanks, List<Pattern> patterns) {
//         super(group, "Reader for " + ((logFileName != null) ? logFileName : logFile.toString()));
      if (logFileName.endsWith(".gz")) {
        try {
          this.logFile = new BufferedReader(new InputStreamReader(new GZIPInputStream(logFile)));
        } catch (IOException e) {
          System.err.println(logFileName + " does not appear to be in gzip format");
          this.logFile = new BufferedReader(new InputStreamReader(logFile));
        }
      } else {
        this.logFile =
          new BufferedReader(new InputStreamReader(logFile));
      }
      this.logFileName = logFileName;
      this.patterns = patterns;
//      this.suppressBlanks = suppressBlanks;
//      this.tabOut = tabOut;
      this.parser = new LogFileParser(this.logFileName, this.logFile, tabOut, suppressBlanks);
    }
 
Example #20
Source File: JavadocParanamer.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
private InputStream urlToInputStream(URL url) throws IOException {
	URLConnection conn = url.openConnection();
	// pretend to be IE6
	conn.setRequestProperty("User-Agent", IE);
	// allow both GZip and Deflate (ZLib) encodings
	conn.setRequestProperty("Accept-Encoding", "gzip, deflate");
	conn.connect();
	String encoding = conn.getContentEncoding();
	if ((encoding != null) && encoding.equalsIgnoreCase("gzip"))
		return new GZIPInputStream(conn.getInputStream());
	else if ((encoding != null) && encoding.equalsIgnoreCase("deflate"))
		return new InflaterInputStream(conn.getInputStream(), new Inflater(
			true));
	else
		return conn.getInputStream();
}
 
Example #21
Source File: HLA.java    From kourami with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private boolean checkHeader(SAMFileHeader header){
List<SAMSequenceRecord> sequences = header.getSequenceDictionary().getSequences();
HashSet<String> map = new HashSet<String>();

//load kourami panel sequence names
BufferedReader br;
try{
    br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(HLA.MSAFILELOC + File.separator + "All_FINAL_with_Decoy.fa.gz"))));
    String curline = "";
    while((curline = br.readLine())!=null){
	if(curline.charAt(0) == ('>'))
	    map.add(curline.substring(1));
    }
    br.close();
}catch(IOException ioe){
    ioe.printStackTrace();
}

//check if input bam has sequences to kourami panel
for(SAMSequenceRecord ssr : sequences){
    if(!map.contains(ssr.getSequenceName()))
	return false;
}
return true;
   }
 
Example #22
Source File: INSECTCompressedMemoryDB.java    From Ngram-Graphs with Apache License 2.0 6 votes vote down vote up
@Override
public TObjectType loadObject(String sObjectName, String sObjectCategory) {
    ByteArrayInputStream bIn = new ByteArrayInputStream((byte[])ObjectMap.get(
            getObjectName(sObjectName, sObjectCategory)));
    TObjectType tObj = null;
    try {
        GZIPInputStream gzIn = new GZIPInputStream(bIn);
        ObjectInputStream oIn = new ObjectInputStream(gzIn);
        tObj = (TObjectType) oIn.readObject();
        oIn.close();
        gzIn.close();
        bIn.close();
    } catch (IOException iOException) {
        System.err.println("Cannot load object from memory. Reason:");
        iOException.printStackTrace(System.err);
    } catch (ClassNotFoundException classNotFoundException) {
        System.err.println("Cannot load object from memory. Reason:");
        classNotFoundException.printStackTrace(System.err);
    }
    
    return tObj;        
}
 
Example #23
Source File: ScoreData.java    From beatoraja with GNU General Public License v3.0 6 votes vote down vote up
public int[] decodeGhost() {
	try {
		if (ghost == null) {
			return null;
		}
		InputStream input = new ByteArrayInputStream(ghost.getBytes());
		InputStream base64 = Base64.getUrlDecoder().wrap(input);
		GZIPInputStream gzip = new GZIPInputStream(base64);
		if (gzip.available() == 0) {
			return null;
		}
		int[] value = new int[notes];
		for (int i=0; i<value.length; i++) {
			int judge = gzip.read();
			value[i] = judge >= 0 ? judge : 4;
		}
		gzip.close();
		return value;
	} catch (IOException e) {
		return null;
	}
}
 
Example #24
Source File: MIRACore.java    From joshua with Apache License 2.0 6 votes vote down vote up
private void gunzipFile(String gzippedFileName, String outputFileName) {
  // NOTE: this will delete the original file

  try {
    GZIPInputStream in = new GZIPInputStream(new FileInputStream(gzippedFileName));
    FileOutputStream out = new FileOutputStream(outputFileName);

    byte[] buffer = new byte[4096];
    int len;
    while ((len = in.read(buffer)) > 0) {
      out.write(buffer, 0, len);
    }

    in.close();
    out.close();

    deleteFile(gzippedFileName);

  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #25
Source File: IntensityLexiconEvaluator.java    From AffectiveTweets with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void processDict() throws IOException  {
	// first, we open the file
	FileInputStream fin = new FileInputStream(this.path);
	GZIPInputStream gzis = new GZIPInputStream(fin);
	InputStreamReader xover = new InputStreamReader(gzis);
	BufferedReader bf = new BufferedReader(xover);

	String line;
	while ((line = bf.readLine()) != null) {
		String pair[] = line.split("\t");
		this.dict.put(pair[0], pair[1]);

	}
	bf.close();
	xover.close();
	gzis.close();
	fin.close();

}
 
Example #26
Source File: CompressedApplicationInputStreamTest.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public void require_that_gnu_tared_file_can_be_unpacked() throws IOException, InterruptedException {
    File tmpTar = File.createTempFile("myapp", ".tar");
    Process p = new ProcessBuilder("tar", "-C", "src/test/resources/deploy/validapp", "--exclude=.svn", "-cvf", tmpTar.getAbsolutePath(), ".").start();
    p.waitFor();
    p = new ProcessBuilder("gzip", tmpTar.getAbsolutePath()).start();
    p.waitFor();
    File gzFile = new File(tmpTar.getAbsolutePath() + ".gz");
    assertTrue(gzFile.exists());
    CompressedApplicationInputStream unpacked = CompressedApplicationInputStream.createFromCompressedStream(
            new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(gzFile))));
    File outApp = unpacked.decompress();
    assertTestApp(outApp);
}
 
Example #27
Source File: FlumePersistentAppenderTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private String getBody(final Event event) throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final InputStream is = new GZIPInputStream(new ByteArrayInputStream(event.getBody()));
    int n = 0;
    while (-1 != (n = is.read())) {
        baos.write(n);
    }
    return new String(baos.toByteArray());

}
 
Example #28
Source File: TestGridmixSubmission.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Expands a file compressed using {@code gzip}.
 *
 * @param fs  the {@code FileSystem} corresponding to the given file.
 * @param in  the path to the compressed file.
 * @param out the path to the uncompressed output.
 * @throws Exception if there was an error during the operation.
 */
private void expandGzippedTrace(FileSystem fs, Path in, Path out)
        throws Exception {
  byte[] buff = new byte[4096];
  GZIPInputStream gis = new GZIPInputStream(fs.open(in));
  FSDataOutputStream fsdOs = fs.create(out);
  int numRead;
  while ((numRead = gis.read(buff, 0, buff.length)) != -1) {
    fsdOs.write(buff, 0, numRead);
  }
  gis.close();
  fsdOs.close();
}
 
Example #29
Source File: MixedMaterialHelper.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
public static MixedMaterial load(Component parent) {
    Configuration config = Configuration.getInstance();
    File terrainDirectory = config.getTerrainDirectory();
    if ((terrainDirectory == null) || (! terrainDirectory.isDirectory())) {
        terrainDirectory = DesktopUtils.getDocumentsFolder();
    }
    File selectedFile = FileUtils.selectFileForOpen(SwingUtilities.getWindowAncestor(parent), "Select WorldPainter custom terrain file", terrainDirectory, new FileFilter() {
        @Override
        public boolean accept(File f) {
            return f.isDirectory() || f.getName().toLowerCase().endsWith(".terrain");
        }

        @Override
        public String getDescription() {
            return "WorldPainter Custom Terrains (*.terrain)";
        }
    });
    if (selectedFile != null) {
        try {
            try (ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(selectedFile))))) {
                return MixedMaterial.duplicateNewMaterialsWhile(() -> (MixedMaterial) in.readObject());
            }
        } catch (IOException e) {
            throw new RuntimeException("I/O error while reading " + selectedFile, e);
        }
    }
    return null;
}
 
Example #30
Source File: ReadUByte.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void realMain(String[] args) throws Throwable {
    try {
        new GZIPInputStream(new BrokenInputStream());
        fail("Failed to throw expected IOException");
    } catch (IOException ex) {
        String msg = ex.getMessage();
        if (msg.indexOf("ReadUByte$BrokenInputStream.read() returned value out of range") < 0) {
            fail("IOException contains incorrect message: '" + msg + "'");
        }
    }
}