package com.epson.cameracopy.alt;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;

/* compiled from: SimpleBmpMerger */
class BmpFileInfo {
    static final /* synthetic */ boolean $assertionsDisabled = false;
    private int mBitPerPixel;
    private int mDataOffset;
    private String mFileName;
    private int mFileSize;
    private int mHeaderSize;
    private int mHeight;
    private int mImageDataBytes;
    private RandomAccessFile mOfs;
    private int mWidth;
    private FileChannel mWriteChannel;

    BmpFileInfo() {
    }

    /* JADX WARNING: Removed duplicated region for block: B:130:0x01bf A[SYNTHETIC, Splitter:B:130:0x01bf] */
    /* JADX WARNING: Removed duplicated region for block: B:134:0x01c6 A[SYNTHETIC, Splitter:B:134:0x01c6] */
    /* JADX WARNING: Removed duplicated region for block: B:141:0x01cd A[SYNTHETIC, Splitter:B:141:0x01cd] */
    /* JADX WARNING: Removed duplicated region for block: B:145:0x01d4 A[SYNTHETIC, Splitter:B:145:0x01d4] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean readParams(java.lang.String r11) {
        /*
            r10 = this;
            r10.mFileName = r11
            java.io.File r0 = new java.io.File
            r0.<init>(r11)
            long r0 = r0.length()
            r2 = 0
            r3 = 0
            java.io.FileInputStream r4 = new java.io.FileInputStream     // Catch:{ IOException -> 0x01ca, all -> 0x01bb }
            r4.<init>(r11)     // Catch:{ IOException -> 0x01ca, all -> 0x01bb }
            java.nio.channels.FileChannel r2 = r4.getChannel()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11 = 512(0x200, float:7.175E-43)
            java.nio.ByteBuffer r11 = java.nio.ByteBuffer.allocate(r11)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11.clear()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.nio.ByteOrder r5 = java.nio.ByteOrder.LITTLE_ENDIAN     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11.order(r5)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r5 = r2.read(r11)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            long r5 = (long) r5
            r7 = 30
            int r9 = (r5 > r7 ? 1 : (r5 == r7 ? 0 : -1))
            if (r9 >= 0) goto L_0x0038
            r4.close()     // Catch:{ IOException -> 0x0032 }
        L_0x0032:
            if (r2 == 0) goto L_0x0037
            r2.close()     // Catch:{ IOException -> 0x0037 }
        L_0x0037:
            return r3
        L_0x0038:
            r11.flip()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            byte r5 = r11.get()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.Byte r5 = java.lang.Byte.valueOf(r5)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            byte r6 = r11.get()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.Byte r6 = java.lang.Byte.valueOf(r6)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            byte r5 = r5.byteValue()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r7 = 66
            if (r5 != r7) goto L_0x01ae
            byte r5 = r6.byteValue()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r6 = 77
            if (r5 == r6) goto L_0x005d
            goto L_0x01ae
        L_0x005d:
            int r5 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mFileSize = r5     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r5 = r10.mFileSize     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            long r5 = (long) r5     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r7 = (r5 > r0 ? 1 : (r5 == r0 ? 0 : -1))
            if (r7 == 0) goto L_0x0098
            java.io.PrintStream r11 = java.lang.System.out     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.StringBuilder r5 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r5.<init>()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r6 = "filesize error. header filesize <"
            r5.append(r6)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r6 = r10.mFileSize     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r5.append(r6)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r6 = ">. actual file size <"
            r5.append(r6)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r5.append(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = ">"
            r5.append(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = r5.toString()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11.println(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r4.close()     // Catch:{ IOException -> 0x0092 }
        L_0x0092:
            if (r2 == 0) goto L_0x0097
            r2.close()     // Catch:{ IOException -> 0x0097 }
        L_0x0097:
            return r3
        L_0x0098:
            r0 = 0
        L_0x0099:
            r1 = 2
            if (r0 >= r1) goto L_0x00ae
            short r1 = r11.getShort()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            if (r1 == 0) goto L_0x00ab
            r4.close()     // Catch:{ IOException -> 0x00a5 }
        L_0x00a5:
            if (r2 == 0) goto L_0x00aa
            r2.close()     // Catch:{ IOException -> 0x00aa }
        L_0x00aa:
            return r3
        L_0x00ab:
            int r0 = r0 + 1
            goto L_0x0099
        L_0x00ae:
            int r0 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mDataOffset = r0     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r0 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mHeaderSize = r0     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r0 = r10.mHeaderSize     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r5 = 40
            if (r0 >= r5) goto L_0x00c9
            r4.close()     // Catch:{ IOException -> 0x00c3 }
        L_0x00c3:
            if (r2 == 0) goto L_0x00c8
            r2.close()     // Catch:{ IOException -> 0x00c8 }
        L_0x00c8:
            return r3
        L_0x00c9:
            int r0 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mWidth = r0     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r0 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mHeight = r0     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            short r0 = r11.getShort()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r5 = 1
            if (r0 == r5) goto L_0x0100
            java.io.PrintStream r11 = java.lang.System.out     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r1.<init>()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r5 = "plain error <"
            r1.append(r5)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r1.append(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = "> != 1"
            r1.append(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = r1.toString()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11.println(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r4.close()     // Catch:{ IOException -> 0x00fa }
        L_0x00fa:
            if (r2 == 0) goto L_0x00ff
            r2.close()     // Catch:{ IOException -> 0x00ff }
        L_0x00ff:
            return r3
        L_0x0100:
            short r0 = r11.getShort()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mBitPerPixel = r0     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r0 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            if (r0 == 0) goto L_0x0130
            java.io.PrintStream r11 = java.lang.System.out     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.StringBuilder r1 = new java.lang.StringBuilder     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r1.<init>()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r5 = "compression error <"
            r1.append(r5)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r1.append(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = "> != 0"
            r1.append(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = r1.toString()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11.println(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r4.close()     // Catch:{ IOException -> 0x012a }
        L_0x012a:
            if (r2 == 0) goto L_0x012f
            r2.close()     // Catch:{ IOException -> 0x012f }
        L_0x012f:
            return r3
        L_0x0130:
            int r11 = r11.getInt()     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r10.mImageDataBytes = r11     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r11 = r10.mImageDataBytes     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r0 = 4
            r6 = 3
            if (r11 != 0) goto L_0x0163
            int r11 = r10.mBitPerPixel     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r7 = 8
            if (r11 == r7) goto L_0x0151
            r7 = 24
            if (r11 == r7) goto L_0x014f
            r4.close()     // Catch:{ IOException -> 0x0149 }
        L_0x0149:
            if (r2 == 0) goto L_0x014e
            r2.close()     // Catch:{ IOException -> 0x014e }
        L_0x014e:
            return r3
        L_0x014f:
            r11 = 3
            goto L_0x0152
        L_0x0151:
            r11 = 1
        L_0x0152:
            int r7 = r10.mWidth     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r11 = r11 * r7
            r7 = r11 & 3
            if (r7 == 0) goto L_0x015d
            int r7 = 4 - r7
            int r11 = r11 + r7
        L_0x015d:
            int r7 = r10.mHeight     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r11 = r11 * r7
            r10.mImageDataBytes = r11     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
        L_0x0163:
            int r11 = r10.mDataOffset     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r7 = r10.mImageDataBytes     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r11 = r11 + r7
            int r7 = r10.mFileSize     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            if (r11 == r7) goto L_0x01a5
            java.io.PrintStream r11 = java.lang.System.out     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r7 = "unsupported data size, file size."
            r11.println(r7)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.io.PrintStream r11 = java.lang.System.out     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.util.Locale r7 = java.util.Locale.US     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r8 = " file size <%d>, data size <%d> data offset <%d>. sum <%d>"
            java.lang.Object[] r0 = new java.lang.Object[r0]     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r9 = r10.mFileSize     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.Integer r9 = java.lang.Integer.valueOf(r9)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r0[r3] = r9     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r9 = r10.mImageDataBytes     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.Integer r9 = java.lang.Integer.valueOf(r9)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r0[r5] = r9     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r9 = r10.mDataOffset     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.Integer r9 = java.lang.Integer.valueOf(r9)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r0[r1] = r9     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r1 = r10.mImageDataBytes     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r9 = r10.mDataOffset     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            int r1 = r1 + r9
            java.lang.Integer r1 = java.lang.Integer.valueOf(r1)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r0[r6] = r1     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            java.lang.String r0 = java.lang.String.format(r7, r8, r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
            r11.println(r0)     // Catch:{ IOException -> 0x01b9, all -> 0x01b7 }
        L_0x01a5:
            r4.close()     // Catch:{ IOException -> 0x01a8 }
        L_0x01a8:
            if (r2 == 0) goto L_0x01ad
            r2.close()     // Catch:{ IOException -> 0x01ad }
        L_0x01ad:
            return r5
        L_0x01ae:
            r4.close()     // Catch:{ IOException -> 0x01b1 }
        L_0x01b1:
            if (r2 == 0) goto L_0x01b6
            r2.close()     // Catch:{ IOException -> 0x01b6 }
        L_0x01b6:
            return r3
        L_0x01b7:
            r11 = move-exception
            goto L_0x01bd
        L_0x01b9:
            goto L_0x01cb
        L_0x01bb:
            r11 = move-exception
            r4 = r2
        L_0x01bd:
            if (r4 == 0) goto L_0x01c4
            r4.close()     // Catch:{ IOException -> 0x01c3 }
            goto L_0x01c4
        L_0x01c3:
        L_0x01c4:
            if (r2 == 0) goto L_0x01c9
            r2.close()     // Catch:{ IOException -> 0x01c9 }
        L_0x01c9:
            throw r11
        L_0x01ca:
            r4 = r2
        L_0x01cb:
            if (r4 == 0) goto L_0x01d2
            r4.close()     // Catch:{ IOException -> 0x01d1 }
            goto L_0x01d2
        L_0x01d1:
        L_0x01d2:
            if (r2 == 0) goto L_0x01d7
            r2.close()     // Catch:{ IOException -> 0x01d7 }
        L_0x01d7:
            return r3
        */
        throw new UnsupportedOperationException("Method not decompiled: com.epson.cameracopy.alt.BmpFileInfo.readParams(java.lang.String):boolean");
    }

    public int getFileSize() {
        return this.mFileSize;
    }

    public int getWidth() {
        return this.mWidth;
    }

    public int getHeight() {
        return this.mHeight;
    }

    public int getBitPerPixel() {
        return this.mBitPerPixel;
    }

    /* JADX DEBUG: Multi-variable search result rejected for TypeSearchVarInfo{r0v3, resolved type: java.nio.channels.FileChannel} */
    /* JADX WARNING: type inference failed for: r0v2 */
    /* JADX WARNING: type inference failed for: r0v4, types: [java.io.FileInputStream] */
    /* JADX WARNING: type inference failed for: r0v5 */
    /* JADX WARNING: type inference failed for: r0v6 */
    /* JADX WARNING: type inference failed for: r0v7 */
    /* JADX WARNING: type inference failed for: r0v8 */
    /* JADX WARNING: type inference failed for: r0v10 */
    /* JADX WARNING: type inference failed for: r0v11 */
    /* JADX WARNING: type inference failed for: r0v12 */
    /* JADX WARNING: Multi-variable type inference failed */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x004f A[SYNTHETIC, Splitter:B:38:0x004f] */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x0056 A[SYNTHETIC, Splitter:B:42:0x0056] */
    /* JADX WARNING: Removed duplicated region for block: B:49:0x0060 A[SYNTHETIC, Splitter:B:49:0x0060] */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x0067 A[SYNTHETIC, Splitter:B:53:0x0067] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public int transferImageData(java.nio.channels.WritableByteChannel r12) {
        /*
            r11 = this;
            int r0 = r11.mImageDataBytes
            r1 = 0
            if (r0 <= 0) goto L_0x006b
            int r0 = r11.mDataOffset
            if (r0 > 0) goto L_0x000b
            goto L_0x006b
        L_0x000b:
            r0 = 0
            java.io.FileInputStream r2 = new java.io.FileInputStream     // Catch:{ IOException -> 0x0048, all -> 0x0045 }
            java.lang.String r3 = r11.mFileName     // Catch:{ IOException -> 0x0048, all -> 0x0045 }
            r2.<init>(r3)     // Catch:{ IOException -> 0x0048, all -> 0x0045 }
            java.nio.channels.FileChannel r0 = r2.getChannel()     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            int r3 = r11.mDataOffset     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            long r5 = (long) r3     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            int r3 = r11.mImageDataBytes     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            long r7 = (long) r3     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            r4 = r0
            r9 = r12
            long r3 = r4.transferTo(r5, r7, r9)     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            int r12 = r11.mImageDataBytes     // Catch:{ IOException -> 0x0040, all -> 0x003e }
            long r5 = (long) r12
            int r12 = (r3 > r5 ? 1 : (r3 == r5 ? 0 : -1))
            if (r12 >= 0) goto L_0x0033
            r2.close()     // Catch:{ IOException -> 0x002d }
        L_0x002d:
            if (r0 == 0) goto L_0x0032
            r0.close()     // Catch:{ IOException -> 0x0032 }
        L_0x0032:
            return r1
        L_0x0033:
            r2.close()     // Catch:{ IOException -> 0x0036 }
        L_0x0036:
            if (r0 == 0) goto L_0x003b
            r0.close()     // Catch:{ IOException -> 0x003b }
        L_0x003b:
            int r12 = r11.mImageDataBytes
            return r12
        L_0x003e:
            r12 = move-exception
            goto L_0x005e
        L_0x0040:
            r12 = move-exception
            r10 = r2
            r2 = r0
            r0 = r10
            goto L_0x004a
        L_0x0045:
            r12 = move-exception
            r2 = r0
            goto L_0x005e
        L_0x0048:
            r12 = move-exception
            r2 = r0
        L_0x004a:
            r12.printStackTrace()     // Catch:{ all -> 0x005a }
            if (r0 == 0) goto L_0x0054
            r0.close()     // Catch:{ IOException -> 0x0053 }
            goto L_0x0054
        L_0x0053:
        L_0x0054:
            if (r2 == 0) goto L_0x0059
            r2.close()     // Catch:{ IOException -> 0x0059 }
        L_0x0059:
            return r1
        L_0x005a:
            r12 = move-exception
            r10 = r2
            r2 = r0
            r0 = r10
        L_0x005e:
            if (r2 == 0) goto L_0x0065
            r2.close()     // Catch:{ IOException -> 0x0064 }
            goto L_0x0065
        L_0x0064:
        L_0x0065:
            if (r0 == 0) goto L_0x006a
            r0.close()     // Catch:{ IOException -> 0x006a }
        L_0x006a:
            throw r12
        L_0x006b:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.epson.cameracopy.alt.BmpFileInfo.transferImageData(java.nio.channels.WritableByteChannel):int");
    }

    public boolean transferImageData(BmpFileInfo bmpFileInfo) {
        int transferImageData = transferImageData(bmpFileInfo.getWritableChannelChannel());
        if (transferImageData <= 0) {
            return false;
        }
        bmpFileInfo.addSize(transferImageData, this.mHeight);
        return true;
    }

    private void writeHeader(FileChannel fileChannel) throws IOException {
        ByteBuffer allocate = ByteBuffer.allocate(54);
        allocate.clear();
        allocate.order(ByteOrder.LITTLE_ENDIAN);
        allocate.put((byte) 66);
        allocate.put((byte) 77);
        allocate.putInt(this.mFileSize);
        allocate.putShort(0);
        allocate.putShort(0);
        allocate.putInt(this.mDataOffset);
        allocate.putInt(this.mHeaderSize);
        allocate.putInt(this.mWidth);
        allocate.putInt(0);
        allocate.putShort(1);
        allocate.putShort((short) this.mBitPerPixel);
        allocate.putInt(0);
        allocate.putInt(this.mImageDataBytes);
        allocate.putInt(0);
        allocate.putInt(0);
        allocate.putInt(0);
        allocate.putInt(0);
        fileChannel.position(0);
        allocate.rewind();
        fileChannel.write(allocate);
    }

    public boolean prepareAppendData() {
        this.mWriteChannel = null;
        try {
            this.mOfs = new RandomAccessFile(this.mFileName, "rw");
            this.mWriteChannel = this.mOfs.getChannel();
            writeHeader(this.mWriteChannel);
            this.mWriteChannel.position((long) this.mDataOffset);
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            RandomAccessFile randomAccessFile = this.mOfs;
            if (randomAccessFile != null) {
                try {
                    randomAccessFile.close();
                } catch (IOException unused) {
                }
            }
            FileChannel fileChannel = this.mWriteChannel;
            if (fileChannel == null) {
                return false;
            }
            try {
                fileChannel.close();
            } catch (IOException unused2) {
            }
            this.mWriteChannel = null;
            return false;
        }
    }

    public void closeWriteableChannel() {
        FileChannel fileChannel = this.mWriteChannel;
        if (fileChannel != null) {
            try {
                fileChannel.close();
            } catch (IOException unused) {
            }
            this.mWriteChannel = null;
        }
        RandomAccessFile randomAccessFile = this.mOfs;
        if (randomAccessFile != null) {
            try {
                randomAccessFile.close();
            } catch (IOException unused2) {
            }
            this.mOfs = null;
        }
    }

    protected WritableByteChannel getWritableChannelChannel() {
        return this.mWriteChannel;
    }

    public boolean updateHeader() {
        ByteBuffer allocate = ByteBuffer.allocate(38);
        allocate.clear();
        allocate.order(ByteOrder.LITTLE_ENDIAN);
        try {
            this.mWriteChannel.position(0);
            if (((long) this.mWriteChannel.read(allocate)) < 38) {
                FileChannel fileChannel = this.mWriteChannel;
                if (fileChannel != null) {
                    try {
                        fileChannel.close();
                    } catch (IOException unused) {
                    }
                    this.mWriteChannel = null;
                }
                RandomAccessFile randomAccessFile = this.mOfs;
                if (randomAccessFile != null) {
                    try {
                        randomAccessFile.close();
                    } catch (IOException unused2) {
                    }
                    this.mOfs = null;
                }
                return false;
            }
            allocate.position(2);
            allocate.putInt(this.mFileSize);
            allocate.position(22);
            allocate.putInt(this.mHeight);
            allocate.position(34);
            allocate.putInt(this.mImageDataBytes);
            allocate.rewind();
            this.mWriteChannel.position(0);
            this.mWriteChannel.write(allocate);
            FileChannel fileChannel2 = this.mWriteChannel;
            if (fileChannel2 != null) {
                try {
                    fileChannel2.close();
                } catch (IOException unused3) {
                }
                this.mWriteChannel = null;
            }
            RandomAccessFile randomAccessFile2 = this.mOfs;
            if (randomAccessFile2 == null) {
                return true;
            }
            try {
                randomAccessFile2.close();
            } catch (IOException unused4) {
            }
            this.mOfs = null;
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            FileChannel fileChannel3 = this.mWriteChannel;
            if (fileChannel3 != null) {
                try {
                    fileChannel3.close();
                } catch (IOException unused5) {
                }
                this.mWriteChannel = null;
            }
            RandomAccessFile randomAccessFile3 = this.mOfs;
            if (randomAccessFile3 != null) {
                try {
                    randomAccessFile3.close();
                } catch (IOException unused6) {
                }
                this.mOfs = null;
            }
            return false;
        } catch (Throwable th) {
            FileChannel fileChannel4 = this.mWriteChannel;
            if (fileChannel4 != null) {
                try {
                    fileChannel4.close();
                } catch (IOException unused7) {
                }
                this.mWriteChannel = null;
            }
            RandomAccessFile randomAccessFile4 = this.mOfs;
            if (randomAccessFile4 != null) {
                try {
                    randomAccessFile4.close();
                } catch (IOException unused8) {
                }
                this.mOfs = null;
            }
            throw th;
        }
    }

    protected void addSize(int i, int i2) {
        this.mFileSize += i;
        this.mImageDataBytes += i;
        this.mHeight += i2;
    }

    public static BmpFileInfo createH0Instance(int i, int i2, String str) {
        BmpFileInfo bmpFileInfo = new BmpFileInfo();
        bmpFileInfo.mFileName = str;
        bmpFileInfo.mHeaderSize = 40;
        bmpFileInfo.mDataOffset = 54;
        bmpFileInfo.mWidth = i;
        bmpFileInfo.mHeight = 0;
        bmpFileInfo.mBitPerPixel = i2;
        bmpFileInfo.mImageDataBytes = 0;
        bmpFileInfo.mFileSize = bmpFileInfo.mDataOffset;
        return bmpFileInfo;
    }
}
