Changeset 343:7f06d669913d
- Timestamp:
- 09/18/11 13:55:15 (5 months ago)
- Branch:
- default
- Convert:
- svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2777
- Location:
- kraken-linux-api
- Files:
-
- 27 edited
-
pom.xml (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/ArpCache.java (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/DnsConfig.java (modified) (3 diffs)
-
src/main/java/org/krakenapps/linux/api/EthernetInterface.java (modified) (4 diffs)
-
src/main/java/org/krakenapps/linux/api/EthernetToolInformation.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/Ipv6NeighborCache.java (modified) (3 diffs)
-
src/main/java/org/krakenapps/linux/api/Ipv6NeighborEntry.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/KernelStat.java (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/MemoryStat.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/NetworkInterface.java (modified) (6 diffs)
-
src/main/java/org/krakenapps/linux/api/NicStat.java (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/Process.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/RoutingEntry.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/RoutingEntryV6.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/RoutingTable.java (modified) (7 diffs)
-
src/main/java/org/krakenapps/linux/api/TcpConnectionInformation.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/UdpConnectionInformation.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/Util.java (modified) (3 diffs)
-
src/main/java/org/krakenapps/linux/api/Wtmp.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/msgbus/ArpCachePlugin.java (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/msgbus/DnsConfigPlugin.java (modified) (3 diffs)
-
src/main/java/org/krakenapps/linux/api/msgbus/EthernetInterfacePlugin.java (modified) (3 diffs)
-
src/main/java/org/krakenapps/linux/api/msgbus/Ipv6Plugin.java (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/msgbus/Marshaler.java (modified) (1 diff)
-
src/main/java/org/krakenapps/linux/api/msgbus/RoutingTablePlugin.java (modified) (2 diffs)
-
src/main/java/org/krakenapps/linux/api/script/LinuxApiScript.java (modified) (5 diffs)
-
src/main/java/org/krakenapps/linux/api/script/LinuxApiScriptFactory.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kraken-linux-api/pom.xml
r206 r343 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <project> 2 <project 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 4 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 3 5 <modelVersion>4.0.0</modelVersion> 4 6 <parent> … … 9 11 <groupId>org.krakenapps</groupId> 10 12 <artifactId>kraken-linux-api</artifactId> 11 <version>1.0. 1</version>13 <version>1.0.2</version> 12 14 <packaging>bundle</packaging> 13 15 <name>Kraken Linux Api</name> -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/ArpCache.java
r156 r343 26 26 } 27 27 28 public static List<ArpEntry> getEntries() {28 public static List<ArpEntry> getEntries() throws FileNotFoundException { 29 29 List<ArpEntry> entries = new ArrayList<ArpEntry>(); 30 30 31 Scanner scanner ;31 Scanner scanner = null; 32 32 try { 33 33 scanner = new Scanner(new File("/proc/net/arp")); … … 96 96 } 97 97 98 } catch (FileNotFoundException e) { 98 } finally { 99 if (scanner != null) 100 scanner.close(); 99 101 } 100 102 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/DnsConfig.java
r2 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 … … 26 41 } 27 42 28 public static DnsConfig getConfig() {43 public static DnsConfig getConfig() throws IOException { 29 44 DnsConfig resolv = new DnsConfig(); 30 45 BufferedReader reader = null; … … 56 71 resolv.others.add(line); 57 72 } 58 } catch (FileNotFoundException e) {59 } catch (IOException e) {60 73 } finally { 61 try { 62 if (reader != null) 63 reader.close(); 64 } catch (IOException e) { 65 e.printStackTrace(); 66 } 74 if (reader != null) 75 reader.close(); 67 76 } 68 77 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/EthernetInterface.java
r2 r343 1 package org.krakenapps.linux.api; 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */package org.krakenapps.linux.api; 2 16 3 17 import java.io.BufferedReader; … … 43 57 private List<AddressBinding> addressBindings; 44 58 45 public EthernetInterface(String device) throws FileNotFoundException {59 public EthernetInterface(String device) throws IOException { 46 60 BufferedReader br = null; 47 61 String line = null; … … 107 121 } 108 122 } 109 } catch (IOException e) {110 e.printStackTrace();111 123 } finally { 112 try {124 if (br != null) 113 125 br.close(); 114 } catch (IOException e) {115 e.printStackTrace();116 }117 126 } 118 127 … … 147 156 subAddr.description.add(line); 148 157 } 149 br.close(); 150 } catch (IOException e) { 151 e.printStackTrace(); 152 } 158 } finally { 159 if (br != null) 160 br.close(); 161 } 162 153 163 addressBindings.add(subAddr); 154 164 } 155 165 } 156 166 157 public static List<EthernetInterface> getEthernetInterfaces() {167 public static List<EthernetInterface> getEthernetInterfaces() throws IOException { 158 168 List<EthernetInterface> interfaces = new ArrayList<EthernetInterface>(); 159 169 String[] filenames = new File(cfgPath).list(new FilenameFilter() { -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/EthernetToolInformation.java
r2 r343 1 package org.krakenapps.linux.api; 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */package org.krakenapps.linux.api; 2 16 3 17 import java.io.IOException; -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/Ipv6NeighborCache.java
r156 r343 1 package org.krakenapps.linux.api; 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */package org.krakenapps.linux.api; 2 16 3 17 import java.io.BufferedReader; … … 11 25 } 12 26 13 public static List<Ipv6NeighborEntry> getEntries() {27 public static List<Ipv6NeighborEntry> getEntries() throws IOException { 14 28 List<Ipv6NeighborEntry> entries = new ArrayList<Ipv6NeighborEntry>(); 15 29 java.lang.Process p = null; 16 30 BufferedReader br = null; 17 31 18 32 try { 19 33 String line = null; 20 34 21 35 p = Runtime.getRuntime().exec("ip -6 neigh show"); 22 36 br = new BufferedReader(new InputStreamReader(p.getInputStream())); 23 37 24 38 while ((line = br.readLine()) != null) { 25 39 String[] values = line.split(" "); … … 28 42 String mac = values[4]; 29 43 String state = values[values.length - 1]; 30 44 31 45 Ipv6NeighborEntry entry = new Ipv6NeighborEntry(address, device, mac, state); 32 46 entries.add(entry); 33 47 } 34 } catch (IOException e) { 48 } finally { 49 if (br != null) 50 br.close(); 35 51 } 52 36 53 return entries; 37 54 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/Ipv6NeighborEntry.java
r156 r343 1 package org.krakenapps.linux.api; 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */package org.krakenapps.linux.api; 2 16 3 17 public class Ipv6NeighborEntry { -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/KernelStat.java
r2 r343 1 /* 2 * Copyright 2010 NCHOVY 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 … … 82 97 KernelStat stat = new KernelStat(); 83 98 BufferedReader br = null; 99 FileInputStream is = null; 84 100 85 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("/proc/stat")))); 86 while (true) { 87 String line = br.readLine(); 88 if (line == null) 89 break; 101 try { 102 is = new FileInputStream(new File("/proc/stat")); 103 br = new BufferedReader(new InputStreamReader(is)); 104 while (true) { 105 String line = br.readLine(); 106 if (line == null) 107 break; 90 108 91 parse(stat, line); 109 parse(stat, line); 110 } 111 112 return stat; 113 } finally { 114 if (is != null) 115 is.close(); 116 if (br != null) 117 br.close(); 92 118 } 93 119 94 try {95 br.close();96 } catch (IOException e) {97 }98 99 return stat;100 120 } 101 121 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/MemoryStat.java
r156 r343 220 220 MemoryStat memory = new MemoryStat(); 221 221 BufferedReader br = null; 222 223 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("/proc/meminfo")))); 224 while (true) { 225 String line = br.readLine(); 226 if (line == null) 227 break; 228 229 parse(memory, line); 222 FileInputStream is = null; 223 224 try { 225 is = new FileInputStream(new File("/proc/meminfo")); 226 br = new BufferedReader(new InputStreamReader(is)); 227 while (true) { 228 String line = br.readLine(); 229 if (line == null) 230 break; 231 232 parse(memory, line); 233 } 234 235 return memory; 236 } finally { 237 if (is != null) 238 is.close(); 239 if (br != null) 240 br.close(); 230 241 } 231 232 try {233 br.close();234 } catch (IOException e) {235 }236 237 return memory;238 242 } 239 243 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/NetworkInterface.java
r2 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 … … 107 122 } 108 123 109 public static List<NetworkInterface> getNetworkInterfaces() {124 public static List<NetworkInterface> getNetworkInterfaces() throws IOException { 110 125 List<NetworkInterface> ifaces = new ArrayList<NetworkInterface>(); 111 126 java.lang.Process p = null; … … 122 137 ifaces.add(iface); 123 138 } 124 } catch (IOException e) {125 e.printStackTrace();126 139 } finally { 127 140 if (p != null) 128 141 p.destroy(); 129 try { 130 if (br != null) 131 br.close(); 132 } catch (IOException e) { 133 e.printStackTrace(); 134 } 142 if (br != null) 143 br.close(); 135 144 } 136 145 … … 258 267 @Override 259 268 public String toString() { 260 return "RxPacket [packets=" + packets + ", errors=" + errors + ", dropped=" + dropped + ", overruns=" 261 + overruns +", frame=" + frame + "]";269 return "RxPacket [packets=" + packets + ", errors=" + errors + ", dropped=" + dropped + ", overruns=" + overruns 270 + ", frame=" + frame + "]"; 262 271 } 263 272 } … … 332 341 @Override 333 342 public String toString() { 334 return "TxPacket [packets=" + packets + ", errors=" + errors + ", dropped=" + dropped + ", overruns=" 335 + overruns +", carrier=" + carrier + ", collisions=" + collisions + ", queuelen=" + queuelen + "]";343 return "TxPacket [packets=" + packets + ", errors=" + errors + ", dropped=" + dropped + ", overruns=" + overruns 344 + ", carrier=" + carrier + ", collisions=" + collisions + ", queuelen=" + queuelen + "]"; 336 345 } 337 346 } … … 339 348 @Override 340 349 public String toString() { 341 return "NetworkInterface [name=" + name + ", linkEncap=" + linkEncap + ", hwaddr=" + hwaddr + ", inet=" + inet 342 + ", ptp=" + ptp + ", mask=" + mask + ", inet6=" + inet6 + ", cidr=" + cidr + ", scope=" + scope343 + ", options=" + options + ", mtu=" + mtu + ", metric=" + metric + ", rxPacket=" + rxPacket344 + ", txPacket=" + txPacket + ", rxBytes=" + rxBytes + ", txBytes=" + txBytes + ", interrupt="345 + interrupt + ", baseAddress=" + baseAddress + ", memory=" +memory + "]";350 return "NetworkInterface [name=" + name + ", linkEncap=" + linkEncap + ", hwaddr=" + hwaddr + ", inet=" + inet + ", ptp=" 351 + ptp + ", mask=" + mask + ", inet6=" + inet6 + ", cidr=" + cidr + ", scope=" + scope + ", options=" + options 352 + ", mtu=" + mtu + ", metric=" + metric + ", rxPacket=" + rxPacket + ", txPacket=" + txPacket + ", rxBytes=" 353 + rxBytes + ", txBytes=" + txBytes + ", interrupt=" + interrupt + ", baseAddress=" + baseAddress + ", memory=" 354 + memory + "]"; 346 355 } 347 356 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/NicStat.java
r156 r343 117 117 List<NicStat> stats = new ArrayList<NicStat>(); 118 118 BufferedReader br = null; 119 120 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("/proc/net/dev")))); 121 br.readLine(); // ignore column name 122 br.readLine(); 123 while (true) { 124 NicStat stat = new NicStat(); 125 String line = br.readLine(); 126 if (line == null) 127 break; 128 129 parse(stat, line); 130 stats.add(stat); 131 } 119 FileInputStream is = null; 132 120 133 121 try { 134 br.close(); 135 } catch (IOException e) { 122 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("/proc/net/dev")))); 123 br.readLine(); // ignore column name 124 br.readLine(); 125 while (true) { 126 NicStat stat = new NicStat(); 127 String line = br.readLine(); 128 if (line == null) 129 break; 130 131 parse(stat, line); 132 stats.add(stat); 133 } 134 135 return stats; 136 } finally { 137 if (is != null) 138 is.close(); 139 if (br != null) 140 br.close(); 136 141 } 137 138 return stats;139 142 } 140 143 … … 169 172 @Override 170 173 public String toString() { 171 return "name=" + name + ", rxBytes=" + rxBytes + ", rxCompressed=" + rxCompressed + ", rxDrops=" 172 + rxDrops + ", rxErrors=" + rxErrors + ", rxFifo=" + rxFifo + ", rxFrames=" + rxFrames173 + ", rx Multicast=" + rxMulticast + ", rxPackets=" + rxPackets + ", txBytes=" + txBytes + ", txCarrier="174 + txCarrier + ", txColls=" + txColls + ", txCompressed=" + txCompressed + ", txDrops=" + txDrops175 + ", tx Errors=" + txErrors + ", txFifo=" + txFifo + ", txPackets=" + txPackets;174 return "name=" + name + ", rxBytes=" + rxBytes + ", rxCompressed=" + rxCompressed + ", rxDrops=" + rxDrops 175 + ", rxErrors=" + rxErrors + ", rxFifo=" + rxFifo + ", rxFrames=" + rxFrames + ", rxMulticast=" + rxMulticast 176 + ", rxPackets=" + rxPackets + ", txBytes=" + txBytes + ", txCarrier=" + txCarrier + ", txColls=" + txColls 177 + ", txCompressed=" + txCompressed + ", txDrops=" + txDrops + ", txErrors=" + txErrors + ", txFifo=" + txFifo 178 + ", txPackets=" + txPackets; 176 179 } 177 180 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/Process.java
r2 r343 157 157 private static void readStatus(File f, Process p) throws IOException { 158 158 BufferedReader br = null; 159 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "status"))));160 161 while (true) {162 String line = br.readLine();163 if (line == null)164 break;165 166 parse(p, line);167 }168 169 159 try { 170 br.close(); 171 } catch (IOException e) { 160 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(f, "status")))); 161 162 while (true) { 163 String line = br.readLine(); 164 if (line == null) 165 break; 166 167 parse(p, line); 168 } 169 } finally { 170 if (br != null) 171 br.close(); 172 172 } 173 173 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/RoutingEntry.java
r2 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/RoutingEntryV6.java
r156 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/RoutingTable.java
r307 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 … … 12 27 13 28 public class RoutingTable { 14 public static List<RoutingEntry> getRoutingEntries() {29 public static List<RoutingEntry> getRoutingEntries() throws IOException { 15 30 List<RoutingEntry> entries = new ArrayList<RoutingEntry>(); 16 31 java.lang.Process p = null; … … 37 52 int use = Integer.parseInt(tokens[6]); 38 53 String iface = tokens[7]; 39 entries.add(new RoutingEntry(destination, gateway, genmask, flags, metric, ref, use, iface, null, 40 null, null)); 54 entries.add(new RoutingEntry(destination, gateway, genmask, flags, metric, ref, use, iface, null, null, null)); 41 55 } else if (tokens.length == 11) { 42 56 InetAddress destination = (!tokens[0].equals("default")) ? InetAddress.getByName(tokens[0]) : null; … … 51 65 int window = Integer.parseInt(tokens[9]); 52 66 int irtt = Integer.parseInt(tokens[10]); 53 entries.add(new RoutingEntry(destination, gateway, genmask, flags, metric, ref, use, iface, mss, 54 window, irtt)); 67 entries.add(new RoutingEntry(destination, gateway, genmask, flags, metric, ref, use, iface, mss, window, irtt)); 55 68 } 56 69 } 57 } catch (IOException e) {58 e.printStackTrace();59 70 } finally { 60 71 if (p != null) 61 72 p.destroy(); 62 try { 63 if (br != null) 64 br.close(); 65 } catch (IOException e) { 66 e.printStackTrace(); 67 } 73 if (br != null) 74 br.close(); 68 75 } 69 76 … … 71 78 } 72 79 73 public static List<RoutingEntryV6> getIpv6RoutingEntries() {80 public static List<RoutingEntryV6> getIpv6RoutingEntries() throws IOException { 74 81 List<RoutingEntryV6> entries = new ArrayList<RoutingEntryV6>(); 75 82 java.lang.Process p = null; … … 106 113 entries.add(new RoutingEntryV6(destination, nextHop, mask, flags, metric, ref, use, iface)); 107 114 } 108 } catch (IOException e) {109 e.printStackTrace();110 115 } finally { 111 116 if (p != null) 112 117 p.destroy(); 113 try { 114 if (br != null) 115 br.close(); 116 } catch (IOException e) { 117 e.printStackTrace(); 118 } 118 if (br != null) 119 br.close(); 119 120 } 120 121 … … 170 171 } 171 172 172 public static RoutingEntry findRoute(InetAddress ip) {173 public static RoutingEntry findRoute(InetAddress ip) throws IOException { 173 174 int target = toInt((Inet4Address) ip); 174 175 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/TcpConnectionInformation.java
r2 r343 79 79 List<ConnectionInformation> stats = new ArrayList<ConnectionInformation>(); 80 80 BufferedReader br = null; 81 82 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)))); 83 br.readLine(); // ignore column name line 84 while (true) { 85 String line = br.readLine(); 86 if (line == null) 87 break; 88 89 if (filePath.endsWith("tcp")) 90 stats.add(parse(line, 4, uidToPid)); 91 else if (filePath.endsWith("tcp6")) 92 stats.add(parse(line, 16, uidToPid)); 93 } 81 FileInputStream is = null; 94 82 95 83 try { 96 br.close(); 97 } catch (IOException e) { 84 is = new FileInputStream(new File(filePath)); 85 br = new BufferedReader(new InputStreamReader(is)); 86 br.readLine(); // ignore column name line 87 while (true) { 88 String line = br.readLine(); 89 if (line == null) 90 break; 91 92 if (filePath.endsWith("tcp")) 93 stats.add(parse(line, 4, uidToPid)); 94 else if (filePath.endsWith("tcp6")) 95 stats.add(parse(line, 16, uidToPid)); 96 } 97 } finally { 98 if (is != null) 99 is.close(); 100 if (br != null) 101 br.close(); 98 102 } 99 103 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/UdpConnectionInformation.java
r2 r343 78 78 List<ConnectionInformation> stats = new ArrayList<ConnectionInformation>(); 79 79 BufferedReader br = null; 80 81 br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)))); 82 br.readLine(); // ignore column name line 83 while (true) { 84 String line = br.readLine(); 85 if (line == null) 86 break; 87 88 if (filePath.endsWith("udp")) 89 stats.add(parse(line, 4, uidToPid)); 90 else if (filePath.endsWith("udp6")) 91 stats.add(parse(line, 16, uidToPid)); 92 } 80 FileInputStream is = null; 93 81 94 82 try { 95 br.close(); 96 } catch (IOException e) { 83 is = new FileInputStream(new File(filePath)); 84 br = new BufferedReader(new InputStreamReader(is)); 85 br.readLine(); // ignore column name line 86 while (true) { 87 String line = br.readLine(); 88 if (line == null) 89 break; 90 91 if (filePath.endsWith("udp")) 92 stats.add(parse(line, 4, uidToPid)); 93 else if (filePath.endsWith("udp6")) 94 stats.add(parse(line, 16, uidToPid)); 95 } 96 } finally { 97 if (is != null) 98 is.close(); 99 if (br != null) 100 br.close(); 97 101 } 98 102 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/Util.java
r2 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api; 2 17 … … 33 48 logger.error("kraken-linux-api: " + line); 34 49 } catch (IOException e) { 35 logger.error("kraken-linux-api: ioerror", e);50 logger.error("kraken-linux-api: run error", e); 36 51 } finally { 37 52 if (p != null) … … 41 56 br.close(); 42 57 } catch (IOException e) { 43 e.printStackTrace();58 logger.error("kraken linux api: run error", e); 44 59 } 45 60 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/Wtmp.java
r2 r343 77 77 } 78 78 79 public static void main(String[] args) throws IOException {80 for (WtmpEntry entry : Wtmp.getEntries()) {81 System.out.println(entry);82 }83 }84 85 79 private static int swap(int v) { 86 80 int a = v; -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/ArpCachePlugin.java
r156 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.msgbus; 17 18 import java.io.FileNotFoundException; 2 19 3 20 import org.apache.felix.ipojo.annotations.Component; … … 12 29 public class ArpCachePlugin { 13 30 @MsgbusMethod 14 public void getEntries(Request req, Response resp) {31 public void getEntries(Request req, Response resp) throws FileNotFoundException { 15 32 resp.put("arp_cache", Marshaler.marshal(ArpCache.getEntries())); 16 33 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/DnsConfigPlugin.java
r5 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.msgbus; 2 17 18 import java.io.IOException; 3 19 import java.net.InetAddress; 4 20 import java.net.UnknownHostException; … … 23 39 24 40 @MsgbusMethod 25 public void getDnsConfig(Request req, Response resp) {41 public void getDnsConfig(Request req, Response resp) throws IOException { 26 42 resp.put("config", Marshaler.marshal(DnsConfig.getConfig())); 27 43 } … … 29 45 @SuppressWarnings("unchecked") 30 46 @MsgbusMethod 31 public void setDnsConfig(Request req, Response resp) {47 public void setDnsConfig(Request req, Response resp) throws IOException { 32 48 try { 33 49 List<InetAddress> nameserver = new ArrayList<InetAddress>(); -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/EthernetInterfacePlugin.java
r5 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.msgbus; 2 17 … … 23 38 24 39 @MsgbusMethod 25 public void getEthernetInterfaces(Request req, Response resp) {40 public void getEthernetInterfaces(Request req, Response resp) throws IOException { 26 41 List<Map<String, Object>> objs = new ArrayList<Map<String, Object>>(); 27 42 List<EthernetInterface> interfaces = EthernetInterface.getEthernetInterfaces(); … … 40 55 @SuppressWarnings("unchecked") 41 56 @MsgbusMethod 42 public void setEthernetInterfaces(Request req, Response resp) {57 public void setEthernetInterfaces(Request req, Response resp) throws IOException { 43 58 Map<String, Object> interfaces = (Map<String, Object>) req.get("interfaces"); 44 59 for (String devname : interfaces.keySet()) { -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/Ipv6Plugin.java
r156 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.msgbus; 17 18 import java.io.IOException; 2 19 3 20 import org.apache.felix.ipojo.annotations.Component; … … 12 29 public class Ipv6Plugin { 13 30 @MsgbusMethod 14 public void getNeighbors(Request req, Response resp) {31 public void getNeighbors(Request req, Response resp) throws IOException { 15 32 resp.put("neighbors", Marshaler.marshal(Ipv6NeighborCache.getEntries())); 16 33 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/Marshaler.java
r156 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.msgbus; 2 17 -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/RoutingTablePlugin.java
r156 r343 1 1 package org.krakenapps.linux.api.msgbus; 2 2 3 import java.io.IOException; 3 4 import java.net.InetAddress; 4 5 import java.net.UnknownHostException; … … 23 24 24 25 @MsgbusMethod 25 public void getRoutingTable(Request req, Response resp) {26 public void getRoutingTable(Request req, Response resp) throws IOException { 26 27 resp.put("routing_table", Marshaler.marshal(RoutingTable.getRoutingEntries())); 27 28 } 28 29 29 30 @MsgbusMethod 30 public void getRoutingTableV6(Request req, Response resp) {31 public void getRoutingTableV6(Request req, Response resp) throws IOException { 31 32 resp.put("routing_table", Marshaler.marshal(RoutingTable.getIpv6RoutingEntries())); 32 33 } -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/script/LinuxApiScript.java
r2 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.script; 2 17 18 import java.io.FileNotFoundException; 3 19 import java.io.IOException; 4 20 import java.net.InetAddress; … … 164 180 } 165 181 166 public void arp(String[] args) {182 public void arp(String[] args) throws FileNotFoundException { 167 183 List<ArpEntry> entries = ArpCache.getEntries(); 168 184 … … 175 191 } 176 192 177 public void routingTable(String[] args) {193 public void routingTable(String[] args) throws IOException { 178 194 List<RoutingEntry> entries = RoutingTable.getRoutingEntries(); 179 195 … … 287 303 } 288 304 289 public void dnsConfig(String[] args) {305 public void dnsConfig(String[] args) throws IOException { 290 306 DnsConfig dns = DnsConfig.getConfig(); 291 307 … … 316 332 @ScriptArgument(name = "second nameserver", type = "string", description = "second nameserver", optional = true), 317 333 @ScriptArgument(name = "third nameserver", type = "string", description = "third nameserver", optional = true) }) 318 public void setNameserver(String[] args) {334 public void setNameserver(String[] args) throws IOException { 319 335 DnsConfig dns = DnsConfig.getConfig(); 320 336 Object[] nameserver = dns.getNameserver().toArray(); -
kraken-linux-api/src/main/java/org/krakenapps/linux/api/script/LinuxApiScriptFactory.java
r2 r343 1 /* 2 * Copyright 2011 Future Systems 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 package org.krakenapps.linux.api.script; 2 17
Note: See TracChangeset
for help on using the changeset viewer.
