Advertisement
goroh_kun

extractbakupのソースコード

May 26th, 2012
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.52 KB | None | 0 0
  1. /*    */ package com.gmail.goroh.kun.tools;
  2. /*    */
  3. /*    */ import java.io.FileInputStream;
  4. /*    */ import java.io.FileNotFoundException;
  5. /*    */ import java.io.FileOutputStream;
  6. /*    */ import java.io.PrintStream;
  7. /*    */ import java.util.zip.Deflater;
  8. /*    */ import java.util.zip.DeflaterOutputStream;
  9. /*    */ import java.util.zip.InflaterInputStream;
  10. /*    */
  11. /*    */ public class ExtractBackup
  12. /*    */ {
  13. /*    */   private static void usage()
  14. /*    */   {
  15. /*  8 */     System.out.println("usage: extractBackup [x|c] backupfile");
  16. /*    */   }
  17. /*    */
  18. /*    */   private static void dumpBytes(byte[] bytes) {
  19. /* 12 */     for (byte b : bytes) {
  20. /* 13 */       System.out.print(" " + Integer.toHexString(b));
  21. /*    */     }
  22. /* 15 */     System.out.println(""); }
  23. /*    */
  24. /*    */   public static void extract(String fname) throws Exception {
  25. /* 18 */     FileInputStream fis = new FileInputStream(fname);
  26. /* 19 */     byte[] buf = new byte[24];
  27. /* 20 */     fis.read(buf);
  28. /* 21 */     dumpBytes(buf);
  29. /* 22 */     FileOutputStream foshdr = new FileOutputStream(fname + ".hdr");
  30. /* 23 */     foshdr.write(buf);
  31. /* 24 */     foshdr.close();
  32. /*    */
  33. /* 26 */     InflaterInputStream iis = new InflaterInputStream(fis);
  34. /* 27 */     FileOutputStream fos = new FileOutputStream(fname + ".tar");
  35. /* 28 */     byte[] buf2 = new byte[65536];
  36. /*    */
  37. /* 30 */     while (iis.available() != 0) {
  38. /* 31 */       int len = iis.read(buf2);
  39. /* 32 */       if (len < 0)
  40. /*    */         break;
  41. /* 34 */       fos.write(buf2, 0, len);
  42. /*    */     }
  43. /* 36 */     fos.close();
  44. /* 37 */     iis.close(); }
  45. /*    */
  46. /*    */   public static void encode(String fname) throws Exception {
  47. /* 40 */     FileOutputStream fos = new FileOutputStream(fname + ".out");
  48. /*    */     try {
  49. /* 42 */       FileInputStream fishdr = new FileInputStream(fname + ".hdr");
  50. /* 43 */       byte[] buf = new byte[24];
  51. /* 44 */       fishdr.read(buf);
  52. /* 45 */       dumpBytes(buf);
  53. /* 46 */       fos.write(buf);
  54. /* 47 */       fishdr.close();
  55. /*    */     } catch (FileNotFoundException e) {
  56. /* 49 */       byte[] buf = {
  57. /* 50 */         65, 78, 68, 82, 79, 73, 68, 32,
  58. /* 51 */         66, 65, 67, 75, 85, 80, 10,
  59. /* 52 */         49, 10, 49, 10, 110, 111, 110, 101, 10 };
  60. /*    */
  61. /* 54 */       dumpBytes(buf);
  62. /* 55 */       fos.write(buf);
  63. /*    */     }
  64. /*    */
  65. /* 58 */     Deflater compresser = new Deflater();
  66. /* 59 */     compresser.setLevel(9);
  67. /*    */
  68. /* 61 */     DeflaterOutputStream dos = new DeflaterOutputStream(fos, compresser);
  69. /* 62 */     FileInputStream fis = new FileInputStream(fname + ".tar");
  70. /* 63 */     byte[] buf2 = new byte[65536];
  71. /*    */
  72. /* 65 */     while (fis.available() != 0) {
  73. /* 66 */       int len = fis.read(buf2);
  74. /* 67 */       if (len < 0)
  75. /*    */         break;
  76. /* 69 */       dos.write(buf2, 0, len);
  77. /*    */     }
  78. /* 71 */     dos.finish();
  79. /* 72 */     fos.close();
  80. /* 73 */     fis.close();
  81. /* 74 */     dos.close(); }
  82. /*    */
  83. /*    */   public static void main(String[] args) throws Exception {
  84. /* 77 */     if (args.length < 2) {
  85. /* 78 */       usage();
  86. /*    */     }
  87. /* 80 */     if ("x".equals(args[0])) {
  88. /* 81 */       extract(args[1]);
  89. /*    */     }
  90. /* 83 */     if ("c".equals(args[0]))
  91. /* 84 */       encode(args[1]);
  92. /*    */   }
  93. /*    */ }
  94.  
  95. /* Location:           C:\android\workspace\testProject\extractbakup.jar
  96.  * Qualified Name:     com.gmail.goroh.kun.tools.ExtractBackup
  97.  * Java Class Version: 6 (50.0)
  98.  * JD-Core Version:    0.5.3
  99.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement