BmpFileInfo.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. package epson.print.Util;
  2. import java.io.IOException;
  3. import java.io.RandomAccessFile;
  4. import java.nio.ByteBuffer;
  5. import java.nio.ByteOrder;
  6. import java.nio.channels.FileChannel;
  7. import java.nio.channels.WritableByteChannel;
  8. public class BmpFileInfo {
  9. static final /* synthetic */ boolean $assertionsDisabled = false;
  10. private int mBitPerPixel;
  11. private int mDataOffset;
  12. private String mFileName;
  13. private int mFileSize;
  14. private int mHeaderSize;
  15. private int mHeight;
  16. private int mImageDataBytes;
  17. private RandomAccessFile mOfs;
  18. private int mWidth;
  19. private FileChannel mWriteChannel;
  20. public boolean readParams(String r11) {
  21. throw new UnsupportedOperationException("Method not decompiled: epson.print.Util.BmpFileInfo.readParams(java.lang.String):boolean");
  22. }
  23. public int getFileSize() {
  24. return mFileSize;
  25. }
  26. public int getWidth() {
  27. return mWidth;
  28. }
  29. public int getHeight() {
  30. return mHeight;
  31. }
  32. public int getBitPerPixel() {
  33. return mBitPerPixel;
  34. }
  35. public int transferImageData(WritableByteChannel r11) {
  36. throw new UnsupportedOperationException("Method not decompiled: epson.print.Util.BmpFileInfo.transferImageData(java.nio.channels.WritableByteChannel):int");
  37. }
  38. public boolean transferImageData(BmpFileInfo bmpFileInfo) {
  39. int transferImageData = transferImageData(bmpFileInfo.getWritableChannelChannel());
  40. if (transferImageData <= 0) {
  41. return false;
  42. }
  43. bmpFileInfo.addSize(transferImageData, mHeight);
  44. return true;
  45. }
  46. private void writeHeader(FileChannel fileChannel) throws IOException {
  47. ByteBuffer allocate = ByteBuffer.allocate(54);
  48. allocate.clear();
  49. allocate.order(ByteOrder.LITTLE_ENDIAN);
  50. allocate.put((byte) 66);
  51. allocate.put((byte) 77);
  52. allocate.putInt(mFileSize);
  53. allocate.putShort((short) 0);
  54. allocate.putShort((short) 0);
  55. allocate.putInt(mDataOffset);
  56. allocate.putInt(mHeaderSize);
  57. allocate.putInt(mWidth);
  58. allocate.putInt(0);
  59. allocate.putShort((short) 1);
  60. allocate.putShort((short) mBitPerPixel);
  61. allocate.putInt(0);
  62. allocate.putInt(mImageDataBytes);
  63. allocate.putInt(0);
  64. allocate.putInt(0);
  65. allocate.putInt(0);
  66. allocate.putInt(0);
  67. fileChannel.position(0);
  68. allocate.rewind();
  69. fileChannel.write(allocate);
  70. }
  71. public boolean prepareAppendData() {
  72. mWriteChannel = null;
  73. try {
  74. mOfs = new RandomAccessFile(mFileName, "rw");
  75. mWriteChannel = mOfs.getChannel();
  76. writeHeader(mWriteChannel);
  77. mWriteChannel.position((long) mDataOffset);
  78. return true;
  79. } catch (IOException e) {
  80. e.printStackTrace();
  81. RandomAccessFile randomAccessFile = mOfs;
  82. if (randomAccessFile != null) {
  83. try {
  84. randomAccessFile.close();
  85. } catch (IOException unused) {
  86. }
  87. }
  88. FileChannel fileChannel = mWriteChannel;
  89. if (fileChannel == null) {
  90. return false;
  91. }
  92. try {
  93. fileChannel.close();
  94. } catch (IOException unused2) {
  95. }
  96. mWriteChannel = null;
  97. return false;
  98. }
  99. }
  100. public void closeWriteableChannel() {
  101. FileChannel fileChannel = mWriteChannel;
  102. if (fileChannel != null) {
  103. try {
  104. fileChannel.close();
  105. } catch (IOException unused) {
  106. }
  107. mWriteChannel = null;
  108. }
  109. RandomAccessFile randomAccessFile = mOfs;
  110. if (randomAccessFile != null) {
  111. try {
  112. randomAccessFile.close();
  113. } catch (IOException unused2) {
  114. }
  115. mOfs = null;
  116. }
  117. }
  118. protected WritableByteChannel getWritableChannelChannel() {
  119. return mWriteChannel;
  120. }
  121. public boolean updateHeader() {
  122. ByteBuffer allocate = ByteBuffer.allocate(38);
  123. allocate.clear();
  124. allocate.order(ByteOrder.LITTLE_ENDIAN);
  125. try {
  126. mWriteChannel.position(0);
  127. if (((long) mWriteChannel.read(allocate)) < 38) {
  128. FileChannel fileChannel = mWriteChannel;
  129. if (fileChannel != null) {
  130. try {
  131. fileChannel.close();
  132. } catch (IOException unused) {
  133. }
  134. mWriteChannel = null;
  135. }
  136. RandomAccessFile randomAccessFile = mOfs;
  137. if (randomAccessFile != null) {
  138. try {
  139. randomAccessFile.close();
  140. } catch (IOException unused2) {
  141. }
  142. mOfs = null;
  143. }
  144. return false;
  145. }
  146. allocate.position(2);
  147. allocate.putInt(mFileSize);
  148. allocate.position(22);
  149. allocate.putInt(mHeight);
  150. allocate.position(34);
  151. allocate.putInt(mImageDataBytes);
  152. allocate.rewind();
  153. mWriteChannel.position(0);
  154. mWriteChannel.write(allocate);
  155. FileChannel fileChannel2 = mWriteChannel;
  156. if (fileChannel2 != null) {
  157. try {
  158. fileChannel2.close();
  159. } catch (IOException unused3) {
  160. }
  161. mWriteChannel = null;
  162. }
  163. RandomAccessFile randomAccessFile2 = mOfs;
  164. if (randomAccessFile2 == null) {
  165. return true;
  166. }
  167. try {
  168. randomAccessFile2.close();
  169. } catch (IOException unused4) {
  170. }
  171. mOfs = null;
  172. return true;
  173. } catch (IOException e) {
  174. e.printStackTrace();
  175. FileChannel fileChannel3 = mWriteChannel;
  176. if (fileChannel3 != null) {
  177. try {
  178. fileChannel3.close();
  179. } catch (IOException unused5) {
  180. }
  181. mWriteChannel = null;
  182. }
  183. RandomAccessFile randomAccessFile3 = mOfs;
  184. if (randomAccessFile3 != null) {
  185. try {
  186. randomAccessFile3.close();
  187. } catch (IOException unused6) {
  188. }
  189. mOfs = null;
  190. }
  191. return false;
  192. } catch (Throwable th) {
  193. FileChannel fileChannel4 = mWriteChannel;
  194. if (fileChannel4 != null) {
  195. try {
  196. fileChannel4.close();
  197. } catch (IOException unused7) {
  198. }
  199. mWriteChannel = null;
  200. }
  201. RandomAccessFile randomAccessFile4 = mOfs;
  202. if (randomAccessFile4 != null) {
  203. try {
  204. randomAccessFile4.close();
  205. } catch (IOException unused8) {
  206. }
  207. mOfs = null;
  208. }
  209. throw th;
  210. }
  211. }
  212. protected void addSize(int i, int i2) {
  213. mFileSize += i;
  214. mImageDataBytes += i;
  215. mHeight += i2;
  216. }
  217. public static BmpFileInfo createH0Instance(int i, int i2, String str) {
  218. BmpFileInfo bmpFileInfo = new BmpFileInfo();
  219. bmpFileInfo.mFileName = str;
  220. bmpFileInfo.mHeaderSize = 40;
  221. bmpFileInfo.mDataOffset = 54;
  222. bmpFileInfo.mWidth = i;
  223. bmpFileInfo.mHeight = 0;
  224. bmpFileInfo.mBitPerPixel = i2;
  225. bmpFileInfo.mImageDataBytes = 0;
  226. bmpFileInfo.mFileSize = bmpFileInfo.mDataOffset;
  227. return bmpFileInfo;
  228. }
  229. }