@Test public void detectedWebPFile() throws Exception { assertThat(isWebPFile(new ByteArrayInputStream("RIFFxxxxWEBP".getBytes("US-ASCII")))).isTrue(); assertThat( isWebPFile(new ByteArrayInputStream("RIFFxxxxxWEBP".getBytes("US-ASCII")))).isFalse(); assertThat(isWebPFile(new ByteArrayInputStream("ABCDxxxxWEBP".getBytes("US-ASCII")))).isFalse(); assertThat(isWebPFile(new ByteArrayInputStream("RIFFxxxxABCD".getBytes("US-ASCII")))).isFalse(); assertThat(isWebPFile(new ByteArrayInputStream("RIFFxxWEBP".getBytes("US-ASCII")))).isFalse(); }
static boolean isWebPFile(InputStream stream) throws IOException { byte[] fileHeaderBytes = new byte[WEBP_FILE_HEADER_SIZE]; boolean isWebPFile = false; if (stream.read(fileHeaderBytes, 0, WEBP_FILE_HEADER_SIZE) == WEBP_FILE_HEADER_SIZE) { isWebPFile = WEBP_FILE_HEADER_RIFF.equals(new String(fileHeaderBytes, 0, 4, "US-ASCII")) && WEBP_FILE_HEADER_WEBP.equals(new String(fileHeaderBytes, 8, 4, "US-ASCII")); } return isWebPFile; }
Utils { static boolean isWebPFile(InputStream stream) throws IOException { byte[] fileHeaderBytes = new byte[WEBP_FILE_HEADER_SIZE]; boolean isWebPFile = false; if (stream.read(fileHeaderBytes, 0, WEBP_FILE_HEADER_SIZE) == WEBP_FILE_HEADER_SIZE) { isWebPFile = WEBP_FILE_HEADER_RIFF.equals(new String(fileHeaderBytes, 0, 4, "US-ASCII")) && WEBP_FILE_HEADER_WEBP.equals(new String(fileHeaderBytes, 8, 4, "US-ASCII")); } return isWebPFile; } }
Utils { static boolean isWebPFile(InputStream stream) throws IOException { byte[] fileHeaderBytes = new byte[WEBP_FILE_HEADER_SIZE]; boolean isWebPFile = false; if (stream.read(fileHeaderBytes, 0, WEBP_FILE_HEADER_SIZE) == WEBP_FILE_HEADER_SIZE) { isWebPFile = WEBP_FILE_HEADER_RIFF.equals(new String(fileHeaderBytes, 0, 4, "US-ASCII")) && WEBP_FILE_HEADER_WEBP.equals(new String(fileHeaderBytes, 8, 4, "US-ASCII")); } return isWebPFile; } private  Utils(); }
Utils { static boolean isWebPFile(InputStream stream) throws IOException { byte[] fileHeaderBytes = new byte[WEBP_FILE_HEADER_SIZE]; boolean isWebPFile = false; if (stream.read(fileHeaderBytes, 0, WEBP_FILE_HEADER_SIZE) == WEBP_FILE_HEADER_SIZE) { isWebPFile = WEBP_FILE_HEADER_RIFF.equals(new String(fileHeaderBytes, 0, 4, "US-ASCII")) && WEBP_FILE_HEADER_WEBP.equals(new String(fileHeaderBytes, 8, 4, "US-ASCII")); } return isWebPFile; } private  Utils();  }
Utils { static boolean isWebPFile(InputStream stream) throws IOException { byte[] fileHeaderBytes = new byte[WEBP_FILE_HEADER_SIZE]; boolean isWebPFile = false; if (stream.read(fileHeaderBytes, 0, WEBP_FILE_HEADER_SIZE) == WEBP_FILE_HEADER_SIZE) { isWebPFile = WEBP_FILE_HEADER_RIFF.equals(new String(fileHeaderBytes, 0, 4, "US-ASCII")) && WEBP_FILE_HEADER_WEBP.equals(new String(fileHeaderBytes, 8, 4, "US-ASCII")); } return isWebPFile; } private  Utils();   }