< prev index next >

src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java

Print this page


   1 /*
   2  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


 270         if (!streams.isEmpty()) {       // unlock and close all remaining streams
 271             Set<InputStream> copy = new HashSet<>(streams);
 272             for (InputStream is: copy)
 273                 is.close();
 274         }
 275         beginWrite();                   // lock and sync
 276         try {
 277             sync();
 278             ch.close();                 // close the ch just in case no update
 279         } finally {                     // and sync dose not close the ch
 280             endWrite();
 281         }
 282 
 283         synchronized (inflaters) {
 284             for (Inflater inf : inflaters)
 285                 inf.end();
 286         }
 287         synchronized (deflaters) {
 288             for (Deflater def : deflaters)
 289                 def.end();








 290         }
 291 
 292         IOException ioe = null;
 293         synchronized (tmppaths) {
 294             for (Path p: tmppaths) {
 295                 try {
 296                     Files.deleteIfExists(p);
 297                 } catch (IOException x) {
 298                     if (ioe == null)
 299                         ioe = x;
 300                     else
 301                         ioe.addSuppressed(x);
 302                 }
 303             }
 304         }
 305         provider.removeFileSystem(zfpath, this);
 306         if (ioe != null)
 307            throw ioe;
 308     }
 309 


   1 /*
   2  * Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
   3  *
   4  * Redistribution and use in source and binary forms, with or without
   5  * modification, are permitted provided that the following conditions
   6  * are met:
   7  *
   8  *   - Redistributions of source code must retain the above copyright
   9  *     notice, this list of conditions and the following disclaimer.
  10  *
  11  *   - Redistributions in binary form must reproduce the above copyright
  12  *     notice, this list of conditions and the following disclaimer in the
  13  *     documentation and/or other materials provided with the distribution.
  14  *
  15  *   - Neither the name of Oracle nor the names of its
  16  *     contributors may be used to endorse or promote products derived
  17  *     from this software without specific prior written permission.
  18  *
  19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR


 270         if (!streams.isEmpty()) {       // unlock and close all remaining streams
 271             Set<InputStream> copy = new HashSet<>(streams);
 272             for (InputStream is: copy)
 273                 is.close();
 274         }
 275         beginWrite();                   // lock and sync
 276         try {
 277             sync();
 278             ch.close();                 // close the ch just in case no update
 279         } finally {                     // and sync dose not close the ch
 280             endWrite();
 281         }
 282 
 283         synchronized (inflaters) {
 284             for (Inflater inf : inflaters)
 285                 inf.end();
 286         }
 287         synchronized (deflaters) {
 288             for (Deflater def : deflaters)
 289                 def.end();
 290         }
 291 
 292         beginWrite();                // lock and sync
 293         try {
 294             // Clear the map so that its keys & values can be garbage collected
 295             inodes = null;
 296         } finally {
 297             endWrite();
 298         }
 299 
 300         IOException ioe = null;
 301         synchronized (tmppaths) {
 302             for (Path p: tmppaths) {
 303                 try {
 304                     Files.deleteIfExists(p);
 305                 } catch (IOException x) {
 306                     if (ioe == null)
 307                         ioe = x;
 308                     else
 309                         ioe.addSuppressed(x);
 310                 }
 311             }
 312         }
 313         provider.removeFileSystem(zfpath, this);
 314         if (ioe != null)
 315            throw ioe;
 316     }
 317 


< prev index next >