21 package org.matsim.core.utils.misc;
23 import java.io.BufferedInputStream;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.util.zip.CRC32;
29 import java.util.zip.CheckedInputStream;
30 import java.util.zip.GZIPInputStream;
32 import org.apache.logging.log4j.LogManager;
33 import org.apache.logging.log4j.Logger;
40 if (in == null)
return 0;
41 CRC32 crc =
new CRC32();
42 try (CheckedInputStream cis =
new CheckedInputStream(in, crc)) {
43 byte[] buffer =
new byte[4096];
44 while (cis.read(buffer) != -1) {
47 check = crc.getValue();
50 catch (IOException e) {
70 log.info(
"filename=" + filename ) ;
71 if (
new File(filename).exists()) {
72 log.info(
"file exists");
73 if (filename.endsWith(
".gz")) {
74 log.info(
"file ends in gz");
75 try ( InputStream in =
new GZIPInputStream(
new BufferedInputStream(
new FileInputStream(filename))) ) {
79 }
catch (IOException e) {
83 log.info(
"file does not end in gz");
84 try ( InputStream in =
new BufferedInputStream(
new FileInputStream(filename)) ) {
88 }
catch (IOException e) {
93 log.info(
"file does not exist; search via class loader");
96 if (filename.endsWith(
".gz")) {
97 log.info(
"file ends in gz");
98 try ( InputStream stream =
CRCChecksum.class.getClassLoader().getResourceAsStream(filename) ;
99 InputStream in =
new GZIPInputStream(
new BufferedInputStream(stream))) {
103 }
catch (IOException e) {
107 log.info(
"file does not end in gz");
108 try ( InputStream stream =
CRCChecksum.class.getClassLoader().getResourceAsStream(filename) ;
109 InputStream in =
new BufferedInputStream(stream)) {
113 }
catch (IOException e) {
static long getCRCFromStream(final InputStream in)
static long getCRCFromFile(final String filename)