@Test public void testValidAIFC() throws IOException, CannotReadException { final int size = 3452; final File aiffFile = createAIFF("FORM", "AIFC", size); try (FileChannel fc = new RandomAccessFile(aiffFile, "rw").getChannel()) { final AiffFileHeader header = new AiffFileHeader(); final AiffAudioHeader aiffAudioHeader = new AiffAudioHeader(); final long remainingBytes = header.readHeader(fc, aiffAudioHeader, aiffFile.toString()); Assert.assertEquals((long)(size - 4), remainingBytes); Assert.assertEquals(AIFC, aiffAudioHeader.getFileType()); } 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);  }