def parse(self):
self.length = os.path.getsize(self.filename)<EOL>with open(self.filename, '<STR_LIT:rb>') as fptr:<EOL><INDENT>read_buffer = fptr.read(<NUM_LIT:2>)<EOL>signature, = struct.unpack('<STR_LIT>', read_buffer)<EOL>if signature == <NUM_LIT>:<EOL><INDENT>self._codec_format = opj2.CODEC_J2K<EOL>return<EOL><DEDENT>self._codec_format = opj2.CODEC_JP2<EOL>fptr.seek(<NUM_LIT:0>)<EOL>read_buffer = fptr.read(<NUM_LIT:12>)<EOL>values = struct.unpack('<STR_LIT>', read_buffer)<EOL>box_length = values[<NUM_LIT:0>]<EOL>box_id = values[<NUM_LIT:1>]<EOL>signature = values[<NUM_LIT:2>:]<EOL>if (((box_length != <NUM_LIT:12>) or (box_id != b'<STR_LIT>') or<EOL>(signature != (<NUM_LIT>, <NUM_LIT:10>, <NUM_LIT>, <NUM_LIT:10>)))):<EOL><INDENT>msg = '<STR_LIT>'<EOL>msg = msg.format(filename=self.filename)<EOL>raise IOError(msg)<EOL><DEDENT>fptr.seek(<NUM_LIT:0>)<EOL>self.box = self.parse_superbox(fptr)<EOL>self._validate()<EOL><DEDENT>
Parses the JPEG 2000 file.

        Raises
        ------
        IOError
            The file was not JPEG 2000.