Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package de.pfabulist.lindwurm.stellvertreter;
  
  
  import java.net.URI;
  import java.nio.file.Path;
 
 import static de.pfabulist.kleinod.errors.Unchecked.runtime;
 import static de.pfabulist.lindwurm.stellvertreter.StellvertreterConstants.ELSEWHEREINFO;
 import static de.pfabulist.lindwurm.stellvertreter.StellvertreterConstants.FSS;
 import static de.pfabulist.lindwurm.stellvertreter.StellvertreterConstants.SALT_FILE;

** BEGIN LICENSE BLOCK ***** BSD License (2 clause) Copyright (c) 2006 - 2014, Stephan Pfab All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Stephan Pfab BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. **** END LICENSE BLOCK ****
 
 public class EncryptedFSElsewhereBuilder implements ElsewhereBuilder {
     private Path host;
     private char[] passwd;
     private Path elsewherePath;
 
     @Override
     public ElsewhereBuilder host(Path host) {
         this. = host;
         return this;
     }
 
     @Override
     public ElsewhereController build() {
         if (  == null ) {
             throw new IllegalStateException"no host" );
         }
 
         Path persisted = .resolve +  );
 
         return new EncryptedElsewhereController(
                 Files.exists(persisted) ? getStoredElsewherepersisted ) : createStoredElsewherepersisted ),
                  == null ? null : getDeEnc());
 
     }
 
     private Path getStoredElsewherePath persisted ) {
         // get
         String stored = null;
         try {
             stored = new String( Files.readAllBytes(persisted), "UTF-8");
         } catch (IOException e) {
             throw new IllegalStateException"can't read store str, possible corrupt" );
         }
 
         Path   storedElsewherePath = Paths.get(URI.create(stored));
 
         if (  != null && !.equals(storedElsewherePath)) {
             throw new IllegalArgumentException("provided elsewhere path different from stored");
         }
 
         return storedElsewherePath;
     }
 
     private Path createStoredElsewherePath persisted )  {
         if (  == null ) {
             throw new IllegalStateException"no elsewhere path is setting up new encryptedfselsewhere" );
         }
 
         Filess.createDirectories();
 
         try {
             Files.writepersisted.toUri().toString().getBytes("UTF-8"));
         } catch (IOException e) {
             throw runtime(e);
         }
 
         return ;
     }
    public static EncryptedFSElsewhereBuilder elsewhere() {
        return new EncryptedFSElsewhereBuilder();
    }
    @Override
    public EncryptedFSElsewhereBuilder password(char[] passwd) {
        this. = passwd;
        return this;
    }
    public ElsewhereBuilder locationPath store ) {
        this. = store;
        return this;
    }
    private DeEnc getDeEnc() {
        Path saltfile = .resolve();
        DeEnc deenc;
        if (!Files.exists(saltfile)) {
            deenc = new DeEnc();
            Filess.write(saltfiledeenc.getSalt());
            return deenc;
        } else {
            deenc = new DeEnc(, Filess.readAllBytes(saltfile));
        }
        return deenc;
    }
New to GrepCode? Check out our FAQ X