/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or the empty String. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(final String magicNumber) { return new MagicNumberFileFilter(magicNumber); }
MagicNumberFileFilter apkFilter = new MagicNumberFileFilter(new byte[] {(byte) 0x50, (byte) 0x4B, (byte) 0x03, (byte) 0x04}); if (!apkFilter.accept(apk)) { return r;
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or is of length zero. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that contains the provided magic * number at a specified offset within the file. * * @param magicNumber the magic number (byte sequence) to match at the * provided offset in each file. * @param offset the offset within the files to look for the magic number. * * @return an IOFileFilter that accepts files containing the magic number * at the specified offset. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or the empty String, or if offset is a * negative number. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(final String magicNumber, final long offset) { return new MagicNumberFileFilter(magicNumber, offset); }
/** * Returns a filter that accepts files that contains the provided magic * number at a specified offset within the file. * * @param magicNumber the magic number (byte sequence) to match at the * provided offset in each file. * @param offset the offset within the files to look for the magic number. * * @return an IOFileFilter that accepts files containing the magic number * at the specified offset. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null}, or contains no bytes, or <code>offset</code> * is a negative number. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber, final long offset) { return new MagicNumberFileFilter(magicNumber, offset); }
@Test public void testMagicNumberFileFilterValidation() { try { new MagicNumberFileFilter((String)null, 0); fail(); } catch (final IllegalArgumentException iae) { new MagicNumberFileFilter("0", -1); fail(); } catch (final IllegalArgumentException iae) { new MagicNumberFileFilter("", 0); fail(); } catch (final IllegalArgumentException iae) { new MagicNumberFileFilter((byte[])null, 0); fail(); } catch (final IllegalArgumentException iae) { new MagicNumberFileFilter(new byte[]{0}, -1); fail(); } catch (final IllegalArgumentException iae) { new MagicNumberFileFilter(new byte[]{}, 0); fail(); } catch (final IllegalArgumentException iae) {
new MagicNumberFileFilter(tarMagicNumber, tarMagicNumberOffset);
new MagicNumberFileFilter(tarMagicNumber, tarMagicNumberOffset);
@Test public void testMagicNumberFileFilterString() throws Exception { final byte[] classFileMagicNumber = new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE}; final String xmlFileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\">\n" + "<element>text</element>"; final String xmlMagicNumber = "<?xml version=\"1.0\""; final File classFileA = new File(getTestDirectory(), "A.class"); final File xmlFileB = new File(getTestDirectory(), "B.xml"); final File dir = new File(getTestDirectory(), "D"); dir.mkdirs(); final OutputStream classFileAStream = FileUtils.openOutputStream(classFileA); IOUtils.write(classFileMagicNumber, classFileAStream); TestUtils.generateTestData(classFileAStream, 32); classFileAStream.close(); FileUtils.write(xmlFileB, xmlFileContent, StandardCharsets.UTF_8); IOFileFilter filter = new MagicNumberFileFilter(xmlMagicNumber); assertFiltering(filter, classFileA, false); assertFiltering(filter, xmlFileB, true); assertFiltering(filter, dir, false); filter = FileFilterUtils.magicNumberFileFilter(xmlMagicNumber); assertFiltering(filter, classFileA, false); assertFiltering(filter, xmlFileB, true); assertFiltering(filter, dir, false); }
@Test public void testMagicNumberFileFilterBytes() throws Exception { final byte[] classFileMagicNumber = new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE}; final String xmlFileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\">\n" + "<element>text</element>"; final File classFileA = new File(getTestDirectory(), "A.class"); final File xmlFileB = new File(getTestDirectory(), "B.xml"); final File emptyFile = new File(getTestDirectory(), "C.xml"); final File dir = new File(getTestDirectory(), "D"); dir.mkdirs(); final OutputStream classFileAStream = FileUtils.openOutputStream(classFileA); IOUtils.write(classFileMagicNumber, classFileAStream); TestUtils.generateTestData(classFileAStream, 32); classFileAStream.close(); FileUtils.write(xmlFileB, xmlFileContent, StandardCharsets.UTF_8); FileUtils.touch(emptyFile); IOFileFilter filter = new MagicNumberFileFilter(classFileMagicNumber); assertFiltering(filter, classFileA, true); assertFiltering(filter, xmlFileB, false); assertFiltering(filter, emptyFile, false); assertFiltering(filter, dir, false); filter = FileFilterUtils.magicNumberFileFilter(classFileMagicNumber); assertFiltering(filter, classFileA, true); assertFiltering(filter, xmlFileB, false); assertFiltering(filter, emptyFile, false); assertFiltering(filter, dir, false); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or is of length zero. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(byte[] magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or the empty String. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(String magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or is of length zero. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(byte[] magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * <code>null</code> or is of length zero. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(byte[] magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or the empty String. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(final String magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * <code>null</code> or the empty String. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(String magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or the empty String. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(String magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or the empty String. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(String magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or is of length zero. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(byte[] magicNumber) { return new MagicNumberFileFilter(magicNumber); }
/** * Returns a filter that accepts files that begin with the provided magic * number. * * @param magicNumber the magic number (byte sequence) to match at the * beginning of each file. * * @return an IOFileFilter that accepts files beginning with the provided * magic number. * * @throws IllegalArgumentException if <code>magicNumber</code> is * {@code null} or is of length zero. * @see MagicNumberFileFilter * @since 2.0 */ public static IOFileFilter magicNumberFileFilter(final byte[] magicNumber) { return new MagicNumberFileFilter(magicNumber); }