Changeset 343:7f06d669913d


Ignore:
Timestamp:
09/18/11 13:55:15 (5 months ago)
Author:
xeraph
Branch:
default
Convert:
svn:7c3792e6-d75b-4784-96a6-b298f655ee64/trunk@2777
Message:
  • fixed potential handle leak bugs.
  • added missing license terms
Location:
kraken-linux-api
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • kraken-linux-api/pom.xml

    r206 r343  
    11<?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"> 
    35        <modelVersion>4.0.0</modelVersion> 
    46        <parent> 
     
    911        <groupId>org.krakenapps</groupId> 
    1012        <artifactId>kraken-linux-api</artifactId> 
    11         <version>1.0.1</version> 
     13        <version>1.0.2</version> 
    1214        <packaging>bundle</packaging> 
    1315        <name>Kraken Linux Api</name> 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/ArpCache.java

    r156 r343  
    2626        } 
    2727 
    28         public static List<ArpEntry> getEntries() { 
     28        public static List<ArpEntry> getEntries() throws FileNotFoundException { 
    2929                List<ArpEntry> entries = new ArrayList<ArpEntry>(); 
    3030 
    31                 Scanner scanner; 
     31                Scanner scanner = null; 
    3232                try { 
    3333                        scanner = new Scanner(new File("/proc/net/arp")); 
     
    9696                        } 
    9797 
    98                 } catch (FileNotFoundException e) { 
     98                } finally { 
     99                        if (scanner != null) 
     100                                scanner.close(); 
    99101                } 
    100102 
  • 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 */ 
    116package org.krakenapps.linux.api; 
    217 
     
    2641        } 
    2742 
    28         public static DnsConfig getConfig() { 
     43        public static DnsConfig getConfig() throws IOException { 
    2944                DnsConfig resolv = new DnsConfig(); 
    3045                BufferedReader reader = null; 
     
    5671                                        resolv.others.add(line); 
    5772                        } 
    58                 } catch (FileNotFoundException e) { 
    59                 } catch (IOException e) { 
    6073                } 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(); 
    6776                } 
    6877 
  • 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; 
    216 
    317import java.io.BufferedReader; 
     
    4357        private List<AddressBinding> addressBindings; 
    4458 
    45         public EthernetInterface(String device) throws FileNotFoundException { 
     59        public EthernetInterface(String device) throws IOException { 
    4660                BufferedReader br = null; 
    4761                String line = null; 
     
    107121                                } 
    108122                        } 
    109                 } catch (IOException e) { 
    110                         e.printStackTrace(); 
    111123                } finally { 
    112                         try { 
     124                        if (br != null) 
    113125                                br.close(); 
    114                         } catch (IOException e) { 
    115                                 e.printStackTrace(); 
    116                         } 
    117126                } 
    118127 
     
    147156                                                subAddr.description.add(line); 
    148157                                } 
    149                                 br.close(); 
    150                         } catch (IOException e) { 
    151                                 e.printStackTrace(); 
    152                         } 
     158                        } finally { 
     159                                if (br != null) 
     160                                        br.close(); 
     161                        } 
     162                         
    153163                        addressBindings.add(subAddr); 
    154164                } 
    155165        } 
    156166 
    157         public static List<EthernetInterface> getEthernetInterfaces() { 
     167        public static List<EthernetInterface> getEthernetInterfaces() throws IOException { 
    158168                List<EthernetInterface> interfaces = new ArrayList<EthernetInterface>(); 
    159169                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; 
    216 
    317import 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; 
    216 
    317import java.io.BufferedReader; 
     
    1125        } 
    1226 
    13         public static List<Ipv6NeighborEntry> getEntries() { 
     27        public static List<Ipv6NeighborEntry> getEntries() throws IOException { 
    1428                List<Ipv6NeighborEntry> entries = new ArrayList<Ipv6NeighborEntry>(); 
    1529                java.lang.Process p = null; 
    1630                BufferedReader br = null; 
    17                  
     31 
    1832                try { 
    1933                        String line = null; 
    20                          
     34 
    2135                        p = Runtime.getRuntime().exec("ip -6 neigh show"); 
    2236                        br = new BufferedReader(new InputStreamReader(p.getInputStream())); 
    23                          
     37 
    2438                        while ((line = br.readLine()) != null) { 
    2539                                String[] values = line.split(" "); 
     
    2842                                String mac = values[4]; 
    2943                                String state = values[values.length - 1]; 
    30                                  
     44 
    3145                                Ipv6NeighborEntry entry = new Ipv6NeighborEntry(address, device, mac, state); 
    3246                                entries.add(entry); 
    3347                        } 
    34                 } catch (IOException e) { 
     48                } finally { 
     49                        if (br != null) 
     50                                br.close(); 
    3551                } 
     52                 
    3653                return entries; 
    3754        } 
  • 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; 
    216 
    317public 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 */ 
    116package org.krakenapps.linux.api; 
    217 
     
    8297                KernelStat stat = new KernelStat(); 
    8398                BufferedReader br = null; 
     99                FileInputStream is = null; 
    84100 
    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; 
    90108 
    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(); 
    92118                } 
    93119 
    94                 try { 
    95                         br.close(); 
    96                 } catch (IOException e) { 
    97                 } 
    98  
    99                 return stat; 
    100120        } 
    101121 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/MemoryStat.java

    r156 r343  
    220220                MemoryStat memory = new MemoryStat(); 
    221221                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(); 
    230241                } 
    231  
    232                 try { 
    233                         br.close(); 
    234                 } catch (IOException e) { 
    235                 } 
    236  
    237                 return memory; 
    238242        } 
    239243 
  • 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 */ 
    116package org.krakenapps.linux.api; 
    217 
     
    107122        } 
    108123 
    109         public static List<NetworkInterface> getNetworkInterfaces() { 
     124        public static List<NetworkInterface> getNetworkInterfaces() throws IOException { 
    110125                List<NetworkInterface> ifaces = new ArrayList<NetworkInterface>(); 
    111126                java.lang.Process p = null; 
     
    122137                                ifaces.add(iface); 
    123138                        } 
    124                 } catch (IOException e) { 
    125                         e.printStackTrace(); 
    126139                } finally { 
    127140                        if (p != null) 
    128141                                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(); 
    135144                } 
    136145 
     
    258267                @Override 
    259268                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 + "]"; 
    262271                } 
    263272        } 
     
    332341                @Override 
    333342                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 + "]"; 
    336345                } 
    337346        } 
     
    339348        @Override 
    340349        public String toString() { 
    341                 return "NetworkInterface [name=" + name + ", linkEncap=" + linkEncap + ", hwaddr=" + hwaddr + ", inet=" + inet 
    342                                 + ", ptp=" + ptp + ", mask=" + mask + ", inet6=" + inet6 + ", cidr=" + cidr + ", scope=" + scope 
    343                                 + ", options=" + options + ", mtu=" + mtu + ", metric=" + metric + ", rxPacket=" + rxPacket 
    344                                 + ", 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 + "]"; 
    346355        } 
    347356} 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/NicStat.java

    r156 r343  
    117117                List<NicStat> stats = new ArrayList<NicStat>(); 
    118118                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; 
    132120 
    133121                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(); 
    136141                } 
    137  
    138                 return stats; 
    139142        } 
    140143 
     
    169172        @Override 
    170173        public String toString() { 
    171                 return "name=" + name + ", rxBytes=" + rxBytes + ", rxCompressed=" + rxCompressed + ", rxDrops=" 
    172                                 + rxDrops + ", rxErrors=" + rxErrors + ", rxFifo=" + rxFifo + ", rxFrames=" + rxFrames 
    173                                 + ", rxMulticast=" + rxMulticast + ", rxPackets=" + rxPackets + ", txBytes=" + txBytes + ", txCarrier=" 
    174                                 + txCarrier + ", txColls=" + txColls + ", txCompressed=" + txCompressed + ", txDrops=" + txDrops 
    175                                 + ", txErrors=" + 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; 
    176179        } 
    177180 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/Process.java

    r2 r343  
    157157        private static void readStatus(File f, Process p) throws IOException { 
    158158                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  
    169159                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(); 
    172172                } 
    173173        } 
  • 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 */ 
    116package org.krakenapps.linux.api; 
    217 
  • 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 */ 
    116package org.krakenapps.linux.api; 
    217 
  • 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 */ 
    116package org.krakenapps.linux.api; 
    217 
     
    1227 
    1328public class RoutingTable { 
    14         public static List<RoutingEntry> getRoutingEntries() { 
     29        public static List<RoutingEntry> getRoutingEntries() throws IOException { 
    1530                List<RoutingEntry> entries = new ArrayList<RoutingEntry>(); 
    1631                java.lang.Process p = null; 
     
    3752                                        int use = Integer.parseInt(tokens[6]); 
    3853                                        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)); 
    4155                                } else if (tokens.length == 11) { 
    4256                                        InetAddress destination = (!tokens[0].equals("default")) ? InetAddress.getByName(tokens[0]) : null; 
     
    5165                                        int window = Integer.parseInt(tokens[9]); 
    5266                                        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)); 
    5568                                } 
    5669                        } 
    57                 } catch (IOException e) { 
    58                         e.printStackTrace(); 
    5970                } finally { 
    6071                        if (p != null) 
    6172                                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(); 
    6875                } 
    6976 
     
    7178        } 
    7279 
    73         public static List<RoutingEntryV6> getIpv6RoutingEntries() { 
     80        public static List<RoutingEntryV6> getIpv6RoutingEntries() throws IOException { 
    7481                List<RoutingEntryV6> entries = new ArrayList<RoutingEntryV6>(); 
    7582                java.lang.Process p = null; 
     
    106113                                entries.add(new RoutingEntryV6(destination, nextHop, mask, flags, metric, ref, use, iface)); 
    107114                        } 
    108                 } catch (IOException e) { 
    109                         e.printStackTrace(); 
    110115                } finally { 
    111116                        if (p != null) 
    112117                                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(); 
    119120                } 
    120121 
     
    170171        } 
    171172 
    172         public static RoutingEntry findRoute(InetAddress ip) { 
     173        public static RoutingEntry findRoute(InetAddress ip) throws IOException { 
    173174                int target = toInt((Inet4Address) ip); 
    174175 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/TcpConnectionInformation.java

    r2 r343  
    7979                List<ConnectionInformation> stats = new ArrayList<ConnectionInformation>(); 
    8080                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; 
    9482 
    9583                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(); 
    98102                } 
    99103 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/UdpConnectionInformation.java

    r2 r343  
    7878                List<ConnectionInformation> stats = new ArrayList<ConnectionInformation>(); 
    7979                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; 
    9381 
    9482                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(); 
    97101                } 
    98102 
  • 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 */ 
    116package org.krakenapps.linux.api; 
    217 
     
    3348                                logger.error("kraken-linux-api: " + line); 
    3449                } catch (IOException e) { 
    35                         logger.error("kraken-linux-api: io error", e); 
     50                        logger.error("kraken-linux-api: run error", e); 
    3651                } finally { 
    3752                        if (p != null) 
     
    4156                                        br.close(); 
    4257                        } catch (IOException e) { 
    43                                 e.printStackTrace(); 
     58                                logger.error("kraken linux api: run error", e); 
    4459                        } 
    4560                } 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/Wtmp.java

    r2 r343  
    7777        } 
    7878 
    79         public static void main(String[] args) throws IOException { 
    80                 for (WtmpEntry entry : Wtmp.getEntries()) { 
    81                         System.out.println(entry); 
    82                 } 
    83         } 
    84  
    8579        private static int swap(int v) { 
    8680                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 */ 
    116package org.krakenapps.linux.api.msgbus; 
     17 
     18import java.io.FileNotFoundException; 
    219 
    320import org.apache.felix.ipojo.annotations.Component; 
     
    1229public class ArpCachePlugin { 
    1330        @MsgbusMethod 
    14         public void getEntries(Request req, Response resp) {  
     31        public void getEntries(Request req, Response resp) throws FileNotFoundException {  
    1532                resp.put("arp_cache", Marshaler.marshal(ArpCache.getEntries())); 
    1633        } 
  • 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 */ 
    116package org.krakenapps.linux.api.msgbus; 
    217 
     18import java.io.IOException; 
    319import java.net.InetAddress; 
    420import java.net.UnknownHostException; 
     
    2339 
    2440        @MsgbusMethod 
    25         public void getDnsConfig(Request req, Response resp) { 
     41        public void getDnsConfig(Request req, Response resp) throws IOException { 
    2642                resp.put("config", Marshaler.marshal(DnsConfig.getConfig())); 
    2743        } 
     
    2945        @SuppressWarnings("unchecked") 
    3046        @MsgbusMethod 
    31         public void setDnsConfig(Request req, Response resp) { 
     47        public void setDnsConfig(Request req, Response resp) throws IOException { 
    3248                try { 
    3349                        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 */ 
    116package org.krakenapps.linux.api.msgbus; 
    217 
     
    2338 
    2439        @MsgbusMethod 
    25         public void getEthernetInterfaces(Request req, Response resp) { 
     40        public void getEthernetInterfaces(Request req, Response resp) throws IOException { 
    2641                List<Map<String, Object>> objs = new ArrayList<Map<String, Object>>(); 
    2742                List<EthernetInterface> interfaces = EthernetInterface.getEthernetInterfaces(); 
     
    4055        @SuppressWarnings("unchecked") 
    4156        @MsgbusMethod 
    42         public void setEthernetInterfaces(Request req, Response resp) { 
     57        public void setEthernetInterfaces(Request req, Response resp) throws IOException { 
    4358                Map<String, Object> interfaces = (Map<String, Object>) req.get("interfaces"); 
    4459                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 */ 
    116package org.krakenapps.linux.api.msgbus; 
     17 
     18import java.io.IOException; 
    219 
    320import org.apache.felix.ipojo.annotations.Component; 
     
    1229public class Ipv6Plugin { 
    1330        @MsgbusMethod 
    14         public void getNeighbors(Request req, Response resp) {  
     31        public void getNeighbors(Request req, Response resp) throws IOException {  
    1532                resp.put("neighbors", Marshaler.marshal(Ipv6NeighborCache.getEntries())); 
    1633        } 
  • 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 */ 
    116package org.krakenapps.linux.api.msgbus; 
    217 
  • kraken-linux-api/src/main/java/org/krakenapps/linux/api/msgbus/RoutingTablePlugin.java

    r156 r343  
    11package org.krakenapps.linux.api.msgbus; 
    22 
     3import java.io.IOException; 
    34import java.net.InetAddress; 
    45import java.net.UnknownHostException; 
     
    2324 
    2425        @MsgbusMethod 
    25         public void getRoutingTable(Request req, Response resp) { 
     26        public void getRoutingTable(Request req, Response resp) throws IOException { 
    2627                resp.put("routing_table", Marshaler.marshal(RoutingTable.getRoutingEntries())); 
    2728        } 
    2829 
    2930        @MsgbusMethod 
    30         public void getRoutingTableV6(Request req, Response resp) { 
     31        public void getRoutingTableV6(Request req, Response resp) throws IOException { 
    3132                resp.put("routing_table", Marshaler.marshal(RoutingTable.getIpv6RoutingEntries())); 
    3233        } 
  • 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 */ 
    116package org.krakenapps.linux.api.script; 
    217 
     18import java.io.FileNotFoundException; 
    319import java.io.IOException; 
    420import java.net.InetAddress; 
     
    164180        } 
    165181 
    166         public void arp(String[] args) { 
     182        public void arp(String[] args) throws FileNotFoundException { 
    167183                List<ArpEntry> entries = ArpCache.getEntries(); 
    168184 
     
    175191        } 
    176192 
    177         public void routingTable(String[] args) { 
     193        public void routingTable(String[] args) throws IOException { 
    178194                List<RoutingEntry> entries = RoutingTable.getRoutingEntries(); 
    179195 
     
    287303        } 
    288304 
    289         public void dnsConfig(String[] args) { 
     305        public void dnsConfig(String[] args) throws IOException { 
    290306                DnsConfig dns = DnsConfig.getConfig(); 
    291307 
     
    316332                        @ScriptArgument(name = "second nameserver", type = "string", description = "second nameserver", optional = true), 
    317333                        @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 { 
    319335                DnsConfig dns = DnsConfig.getConfig(); 
    320336                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 */ 
    116package org.krakenapps.linux.api.script; 
    217 
Note: See TracChangeset for help on using the changeset viewer.