Examples of RiakTemplate


Examples of org.springframework.data.keyvalue.riak.core.RiakTemplate

      System.err.println("Error parsing command line: " + e.getMessage());
    }

    if (null != cl) {
      boolean verbose = cl.hasOption('v');
      RiakTemplate riak = new RiakTemplate();
      riak.getRestTemplate().setErrorHandler(new Ignore404sErrorHandler());
      if (cl.hasOption('u')) {
        riak.setDefaultUri(cl.getOptionValue('u'));
      }
      try {
        riak.afterPropertiesSet();
      } catch (Exception e) {
        System.err.println("Error creating RiakTemplate: " + e.getMessage());
      }
      String[] files = cl.getOptionValues('j');
      if (null != files) {
        for (String file : files) {
          if (verbose) {
            System.out.println(String.format("Loading JAR file %s into Riak...", file));
          }
          try {
            File zfile = new File(file);
            ZipInputStream zin = new ZipInputStream(new FileInputStream(zfile));
            ZipEntry entry;
            while (null != (entry = zin.getNextEntry())) {
              ByteArrayOutputStream bout = new ByteArrayOutputStream();
              byte[] buff = new byte[16384];
              for (int bytesRead = zin.read(buff); bytesRead > 0; bytesRead = zin.read(buff)) {
                bout.write(buff, 0, bytesRead);
              }

              if (entry.getName().endsWith(".class")) {
                String name = entry.getName().replaceAll("/", ".");
                name = URLEncoder.encode(name.substring(0, name.length() - 6), "UTF-8");
                String bucket;
                if (cl.hasOption('b')) {
                  bucket = cl.getOptionValue('b');
                } else {
                  bucket = URLEncoder.encode(zfile.getCanonicalFile().getName(), "UTF-8");
                }
                if (verbose) {
                  System.out.println(String.format("Uploading to %s/%s", bucket, name));
                }

                // Load these bytes into Riak
                riak.setAsBytes(bucket, name, bout.toByteArray());
              }
            }
          } catch (FileNotFoundException e) {
            System.err.println("Error reading JAR file: " + e.getMessage());
          } catch (IOException e) {
            System.err.println("Error reading JAR file: " + e.getMessage());
          }
        }
      }

      String[] classFiles = cl.getOptionValues('c');
      if (null != classFiles) {
        for (String classFile : classFiles) {
          try {
            FileInputStream fin = new FileInputStream(classFile);
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            byte[] buff = new byte[16384];
            for (int bytesRead = fin.read(buff); bytesRead > 0; bytesRead = fin.read(buff)) {
              bout.write(buff, 0, bytesRead);
            }

            String name;
            if (cl.hasOption('k')) {
              name = cl.getOptionValue('k');
            } else {
              throw new IllegalStateException(
                  "Must specify a Riak key in which to store the data if loading individual class files.");
            }
            String bucket;
            if (cl.hasOption('b')) {
              bucket = cl.getOptionValue('b');
            } else {
              throw new IllegalStateException(
                  "Must specify a Riak bucket in which to store the data if loading individual class files.");
            }
            if (verbose) {
              System.out.println(String.format("Uploading to %s/%s", bucket, name));
            }

            // Load these bytes into Riak
            riak.setAsBytes(bucket, name, bout.toByteArray());

          } catch (FileNotFoundException e) {
            System.err.println("Error reading class file: " + e.getMessage());
          } catch (IOException e) {
            System.err.println("Error reading class file: " + e.getMessage());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.