@Test public void testInvalidFormat2() throws IOException, CannotReadException { final int size = 34234; final File aiffFile = createAIFF("FORMA", "AIFF", size); try (FileChannel fc = new RandomAccessFile(aiffFile, "rw").getChannel()) { new AiffFileHeader().readHeader(fc, new AiffAudioHeader(), aiffFile.toString()); Assert.fail("Expected " + CannotReadException.class.getSimpleName()); } catch (CannotReadException e) { } aiffFile.delete(); }
public long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName) throws IOException, CannotReadException { final ByteBuffer headerData = ByteBuffer.allocateDirect(HEADER_LENGTH); headerData.order(BIG_ENDIAN); final int bytesRead = fc.read(headerData); headerData.position(0); if (bytesRead < HEADER_LENGTH) { throw new IOException( fileName + " AIFF:Unable to read required number of databytes read:" + bytesRead + ":required:" + HEADER_LENGTH); } final String signature = Utils.readFourBytesAsChars(headerData); if (FORM.equals(signature)) { final long chunkSize = headerData.getInt(); LOG.log(ERROR, "$1%s Reading AIFF header size:$2%d 0x$2%x", fileName, chunkSize); readFileType(headerData, aiffAudioHeader); return chunkSize - TYPE_LENGTH; } else { throw new CannotReadException(fileName + "Not an AIFF file: incorrect signature " + signature); } }
AiffFileHeader { public long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName) throws IOException, CannotReadException { final ByteBuffer headerData = ByteBuffer.allocateDirect(HEADER_LENGTH); headerData.order(BIG_ENDIAN); final int bytesRead = fc.read(headerData); headerData.position(0); if (bytesRead < HEADER_LENGTH) { throw new IOException( fileName + " AIFF:Unable to read required number of databytes read:" + bytesRead + ":required:" + HEADER_LENGTH); } final String signature = Utils.readFourBytesAsChars(headerData); if (FORM.equals(signature)) { final long chunkSize = headerData.getInt(); LOG.log(ERROR, "$1%s Reading AIFF header size:$2%d 0x$2%x", fileName, chunkSize); readFileType(headerData, aiffAudioHeader); return chunkSize - TYPE_LENGTH; } else { throw new CannotReadException(fileName + "Not an AIFF file: incorrect signature " + signature); } } }
AiffFileHeader { public long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName) throws IOException, CannotReadException { final ByteBuffer headerData = ByteBuffer.allocateDirect(HEADER_LENGTH); headerData.order(BIG_ENDIAN); final int bytesRead = fc.read(headerData); headerData.position(0); if (bytesRead < HEADER_LENGTH) { throw new IOException( fileName + " AIFF:Unable to read required number of databytes read:" + bytesRead + ":required:" + HEADER_LENGTH); } final String signature = Utils.readFourBytesAsChars(headerData); if (FORM.equals(signature)) { final long chunkSize = headerData.getInt(); LOG.log(ERROR, "$1%s Reading AIFF header size:$2%d 0x$2%x", fileName, chunkSize); readFileType(headerData, aiffAudioHeader); return chunkSize - TYPE_LENGTH; } else { throw new CannotReadException(fileName + "Not an AIFF file: incorrect signature " + signature); } }  }
AiffFileHeader { public long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName) throws IOException, CannotReadException { final ByteBuffer headerData = ByteBuffer.allocateDirect(HEADER_LENGTH); headerData.order(BIG_ENDIAN); final int bytesRead = fc.read(headerData); headerData.position(0); if (bytesRead < HEADER_LENGTH) { throw new IOException( fileName + " AIFF:Unable to read required number of databytes read:" + bytesRead + ":required:" + HEADER_LENGTH); } final String signature = Utils.readFourBytesAsChars(headerData); if (FORM.equals(signature)) { final long chunkSize = headerData.getInt(); LOG.log(ERROR, "$1%s Reading AIFF header size:$2%d 0x$2%x", fileName, chunkSize); readFileType(headerData, aiffAudioHeader); return chunkSize - TYPE_LENGTH; } else { throw new CannotReadException(fileName + "Not an AIFF file: incorrect signature " + signature); } }  long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName); }
AiffFileHeader { public long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName) throws IOException, CannotReadException { final ByteBuffer headerData = ByteBuffer.allocateDirect(HEADER_LENGTH); headerData.order(BIG_ENDIAN); final int bytesRead = fc.read(headerData); headerData.position(0); if (bytesRead < HEADER_LENGTH) { throw new IOException( fileName + " AIFF:Unable to read required number of databytes read:" + bytesRead + ":required:" + HEADER_LENGTH); } final String signature = Utils.readFourBytesAsChars(headerData); if (FORM.equals(signature)) { final long chunkSize = headerData.getInt(); LOG.log(ERROR, "$1%s Reading AIFF header size:$2%d 0x$2%x", fileName, chunkSize); readFileType(headerData, aiffAudioHeader); return chunkSize - TYPE_LENGTH; } else { throw new CannotReadException(fileName + "Not an AIFF file: incorrect signature " + signature); } }  long readHeader(FileChannel fc, final AiffAudioHeader aiffAudioHeader, String fileName);  }