Add packetcable-driver as a bundle and fix karafe depends. Merge hop-along model...
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / utils / PCMMUtils.java
1 /**
2  @header@
3  */
4 package org.pcmm.utils;
5
6 import java.io.FileInputStream;
7 import java.io.FileNotFoundException;
8 import java.io.FileOutputStream;
9 import java.io.IOException;
10
11 public class PCMMUtils {
12
13     public static void WriteBinaryDump(String rootFileName, byte[] buffer) {
14         // Make this Unique
15         String fileName = "/tmp/" + rootFileName + "-" + java.util.UUID.randomUUID() + ".bin";
16         try {
17
18             System.out.println("Open fileName " + fileName);
19             FileOutputStream outputStream = new FileOutputStream(fileName);
20
21             // write() writes as many bytes from the buffer
22             // as the length of the buffer. You can also
23             // use
24             // write(buffer, offset, length)
25             // if you want to write a specific number of
26             // bytes, or only part of the buffer.
27             outputStream.write(buffer);
28
29             // Always close files.
30             outputStream.close();
31
32             System.out.println("Wrote " + buffer.length + " bytes");
33         } catch (IOException ex) {
34             System.out.println("Error writing file '" + fileName + "'");
35             // Or we could just do this:
36             // ex.printStackTrace();
37         }
38     }
39
40     public static byte[] ReadBinaryDump(String fileName) {
41         // The name of the file to open.
42         // String fileName = "COPSReportMessage.txt";
43         try {
44             FileInputStream inputStream = new FileInputStream(fileName);
45             // Use this for reading the data.
46             byte[] buffer = new byte[inputStream.available()];
47             // read fills buffer with data and returns
48             // the number of bytes read (which of course
49             // may be less than the buffer size, but
50             // it will never be more).
51             int total = inputStream.read(buffer);
52
53             // Always close files.
54             inputStream.close();
55
56             System.out.println("Read " + total + " bytes");
57             return buffer;
58         } catch (FileNotFoundException ex) {
59             System.out.println("Unable to open file '" + fileName + "'");
60         } catch (IOException ex) {
61             System.out.println("Error reading file '" + fileName + "'");
62             // Or we could just do this:
63             // ex.printStackTrace();
64         }
65         return null;
66     }
67 }