jdk/src/share/classes/sun/security/krb5/internal/ktab/KeyTab.java
changeset 9542 6f715a596a2e
parent 9499 f3115698a012
child 11911 f960f3b33af3
equal deleted inserted replaced
9541:7ce475045bf0 9542:6f715a596a2e
    90      */
    90      */
    91     private KeyTab(String filename) {
    91     private KeyTab(String filename) {
    92         tabName = filename;
    92         tabName = filename;
    93         try {
    93         try {
    94             lastModified = new File(tabName).lastModified();
    94             lastModified = new File(tabName).lastModified();
    95             KeyTabInputStream kis =
    95             try (KeyTabInputStream kis =
    96                 new KeyTabInputStream(new FileInputStream(filename));
    96                     new KeyTabInputStream(new FileInputStream(filename))) {
    97             load(kis);
    97                 load(kis);
    98             kis.close();
    98             }
    99         } catch (FileNotFoundException e) {
    99         } catch (FileNotFoundException e) {
   100             entries.clear();
   100             entries.clear();
   101             isMissing = true;
   101             isMissing = true;
   102         } catch (Exception ioe) {
   102         } catch (Exception ioe) {
   103             entries.clear();
   103             entries.clear();
   437      * Creates a new default key table.
   437      * Creates a new default key table.
   438      */
   438      */
   439     public synchronized static KeyTab create(String name)
   439     public synchronized static KeyTab create(String name)
   440         throws IOException, RealmException {
   440         throws IOException, RealmException {
   441 
   441 
   442         KeyTabOutputStream kos =
   442         try (KeyTabOutputStream kos =
   443                 new KeyTabOutputStream(new FileOutputStream(name));
   443                 new KeyTabOutputStream(new FileOutputStream(name))) {
   444         kos.writeVersion(KRB5_KT_VNO);
   444             kos.writeVersion(KRB5_KT_VNO);
   445         kos.close();
   445         }
   446         return new KeyTab(name);
   446         return new KeyTab(name);
   447     }
   447     }
   448 
   448 
   449     /**
   449     /**
   450      * Saves the file at the directory.
   450      * Saves the file at the directory.
   451      */
   451      */
   452     public synchronized void save() throws IOException {
   452     public synchronized void save() throws IOException {
   453         KeyTabOutputStream kos =
   453         try (KeyTabOutputStream kos =
   454                 new KeyTabOutputStream(new FileOutputStream(tabName));
   454                 new KeyTabOutputStream(new FileOutputStream(tabName))) {
   455         kos.writeVersion(kt_vno);
   455             kos.writeVersion(kt_vno);
   456         for (int i = 0; i < entries.size(); i++) {
   456             for (int i = 0; i < entries.size(); i++) {
   457             kos.writeEntry(entries.elementAt(i));
   457                 kos.writeEntry(entries.elementAt(i));
   458         }
   458             }
   459         kos.close();
   459         }
   460     }
   460     }
   461 
   461 
   462     /**
   462     /**
   463      * Removes entries from the key table.
   463      * Removes entries from the key table.
   464      * @param service the service <code>PrincipalName</code>.
   464      * @param service the service <code>PrincipalName</code>.
   517      * Creates key table file version.
   517      * Creates key table file version.
   518      * @param file the key table file.
   518      * @param file the key table file.
   519      * @exception IOException.
   519      * @exception IOException.
   520      */
   520      */
   521     public synchronized void createVersion(File file) throws IOException {
   521     public synchronized void createVersion(File file) throws IOException {
   522         KeyTabOutputStream kos =
   522         try (KeyTabOutputStream kos =
   523                 new KeyTabOutputStream(new FileOutputStream(file));
   523                 new KeyTabOutputStream(new FileOutputStream(file))) {
   524         kos.write16(KRB5_KT_VNO);
   524             kos.write16(KRB5_KT_VNO);
   525         kos.close();
   525         }
   526     }
   526     }
   527 }
   527 }