return false;
}
input.mark(4);
- byte[] bytes = new byte[2]; // input.readNBytes(2);
+
+ // get first 2 bytes or return false
+ byte[] bytes = new byte[2];
int read = input.read(bytes);
input.reset();
if (read != bytes.length)
{
return false;
}
- if (bytes.length == 2)
- {
- int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
- return (GZIPInputStream.GZIP_MAGIC == header);
- }
- return false;
+
+ int header = (bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);
+ return (GZIPInputStream.GZIP_MAGIC == header);
}
/**
import static org.testng.Assert.assertTrue;
import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringBufferInputStream;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterClass;
*/
is = new BufferedInputStream(is, 16);
assertTrue(FileParse.isGzipStream(is));
+
+ /*
+ * check recognition of non-gzipped input
+ */
+ assertFalse(FileParse.isGzipStream(new BufferedInputStream(
+ new ByteArrayInputStream("NOT A GZIP".getBytes()))));
}
@Test(groups = { "Functional" })