s243a

ErrorArchiveStoreItem.java (freenet.client)

Oct 22nd, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. // s243a pearltree node: http://www.pearltrees.com/s243a/java-freenet-client/id12827785
  2. /* This code is part of Freenet. It is distributed under the GNU General
  3.  * Public License, version 2 (or at your option any later version). See
  4.  * http://www.gnu.org/ for further details of the GPL. */
  5. package freenet.client;
  6.  
  7. import freenet.keys.FreenetURI;
  8. import freenet.support.api.Bucket;
  9.  
  10. class ErrorArchiveStoreItem extends ArchiveStoreItem {
  11.  
  12.     /** Error message. Usually something about the file being too big. */
  13.     String error;
  14.     boolean tooBig;
  15.    
  16.     /**
  17.      * Create a placeholder item for a file which could not be extracted from the archive.
  18.      * @param ctx The context object which tracks all the items with this key.
  19.      * @param key2 The key from which the archive was fetched.
  20.      * @param name The name of the file which failed to extract.
  21.      * @param error The error message to be included in the thrown exception when
  22.      * somebody tries to get the data.
  23.      */
  24.     public ErrorArchiveStoreItem(ArchiveStoreContext ctx, FreenetURI key2, String name, String error, boolean tooBig) {
  25.         super(new ArchiveKey(key2, name), ctx);
  26.         this.error = error;
  27.         this.tooBig = tooBig;
  28.     }
  29.  
  30.     /**
  31.      * Throws an exception with the given error message, because this file could not be
  32.      * extracted from the archive.
  33.      */
  34.     @Override
  35.     Bucket getDataOrThrow() throws ArchiveFailureException {
  36.         throw new ArchiveFailureException(error);
  37.     }
  38.  
  39.     @Override
  40.     public long spaceUsed() {
  41.         return 0;
  42.     }
  43.  
  44.     @Override
  45.     Bucket getReaderBucket() throws ArchiveFailureException {
  46.         if(tooBig) return null;
  47.         throw new ArchiveFailureException(error);
  48.     }
  49.    
  50.     public boolean tooBig() {
  51.         return tooBig;
  52.     }
  53.    
  54. }
Add Comment
Please, Sign In to add comment