Package com.google.k2crypto.storage

Examples of com.google.k2crypto.storage.StoreIOException


        // Prepare if not cached
        stmt =
            connection.prepareStatement("SELECT data FROM Keys WHERE id = ?");
        stmt.setString(1, keyIdentifier);
      } catch (SQLException ex) {
        throw new StoreIOException(StoreIOException.Reason.DRIVER_SPECIFIC, ex);
      }
      selectStmt = stmt;
    }

    // Execute query and return data if requested
    ResultSet results = null;
    try {
      results = stmt.executeQuery();
      if (results.next()) {
        return retrieveData ? results.getBytes(1) : KEY_EXISTS;
      }
    } catch (SQLException ex) {
      throw new StoreIOException(StoreIOException.Reason.READ_ERROR, ex);
    } finally {
      try { results.close(); }
      catch (Exception ex) {}
    }
    return null;
View Full Code Here


    ExtensionRegistry registry =
        context.getKeyVersionRegistry().getProtoExtensions();
    try {
      return new Key(context, KeyData.parseFrom(bytes, registry));
    } catch (IOException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.READ_ERROR, ex);
    } catch (InvalidKeyDataException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.DESERIALIZATION_ERROR, ex);
    } catch (UnregisteredKeyVersionException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.UNREGISTERED_KEY_VERSION, ex);
    }
  }
View Full Code Here

        stmt = connection.prepareStatement(
            "INSERT OR REPLACE INTO Keys (id, data, modified) "
            + "VALUES (?, ?, datetime('now'))");
        stmt.setString(1, keyIdentifier);
      } catch (SQLException ex) {
        throw new StoreIOException(StoreIOException.Reason.DRIVER_SPECIFIC, ex);
      }
      insertStmt = stmt;
    }
   
    // Convert key contents to byte array
    ByteString bytes;
    try {
      bytes = key.buildData().build().toByteString();
    } catch (RuntimeException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.SERIALIZATION_ERROR, ex);
    }
   
    // Insert/update key in database table
    try {
      stmt.setBytes(2, bytes.toByteArray());
      stmt.executeUpdate();
    } catch (SQLException ex) {
      throw new StoreIOException(StoreIOException.Reason.WRITE_ERROR, ex);
    }   
  }
View Full Code Here

      try {
        // Prepare if not cached
        stmt = connection.prepareStatement("DELETE FROM Keys WHERE id = ?");
        stmt.setString(1, keyIdentifier);
      } catch (SQLException ex) {
        throw new StoreIOException(StoreIOException.Reason.DRIVER_SPECIFIC, ex);
      }
      deleteStmt = stmt;
    }
   
    // Remove key from database table
    try {
      return stmt.executeUpdate() > 0;
    } catch (SQLException ex) {
      throw new StoreIOException(StoreIOException.Reason.WRITE_ERROR, ex);
    }
  }
View Full Code Here

      other.delete();
     
      // Move primary to the now empty 'other' slot,
      // then move 'target' slot to the primary.
      if (!keyFile.renameTo(other) || !target.renameTo(keyFile)) {
        throw new StoreIOException(
            StoreIOException.Reason.WRITE_ERROR);
      }
     
    } else {
      // Primary does not exist; just write directly to the primary slot
View Full Code Here

      CodedOutputStream cos = CodedOutputStream.newInstance(bytes);
      data.writeTo(cos);
      cos.checkNoSpaceLeft();
      return bytes;
    } catch (Exception ex) {
      throw new StoreIOException(
          StoreIOException.Reason.SERIALIZATION_ERROR, ex);
    }
  }
View Full Code Here

      try { out.close(); }
      catch (Exception ex) {}
    }
    if (exception != null || file.length() != keyBytes.length) {
      file.delete();
      throw new StoreIOException(
          StoreIOException.Reason.WRITE_ERROR, exception);
    }
  }
View Full Code Here

        new File[] { keyFile, tempFileB, tempFileA };
   
    // Attempt to read each file and return the first successfully parsed Key
    ExtensionRegistry registry =
        context.getKeyVersionRegistry().getProtoExtensions();
    StoreIOException ioException = null;
    for (File file : candidates) {
      try {
        if (file != null) {
          return readKey(file, registry);
        }
      } catch (StoreIOException ex) {
        // Retain the highest-level exception (i.e. the furthest we have gotten)
        if (ioException == null
            || ex.getReason().compareTo(ioException.getReason()) < 0) {
          ioException = ex;
        }
      }
    }
   
View Full Code Here

    FileInputStream in = null;
    try {
      in = new FileInputStream(file);
      return new Key(context, KeyData.parseFrom(in, registry));
    } catch (IOException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.READ_ERROR, ex);
    } catch (InvalidKeyDataException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.DESERIALIZATION_ERROR, ex);
    } catch (UnregisteredKeyVersionException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.UNREGISTERED_KEY_VERSION, ex);
    } finally {
      try { in.close(); }
      catch (Exception ex) {}
    }
View Full Code Here

  public void save(Key key) throws StoreException {
    KeyData data;
    try {
      data = key.buildData().build();
    } catch (RuntimeException ex) {
      throw new StoreIOException(
          StoreIOException.Reason.SERIALIZATION_ERROR, ex);
    }
    memSpace.save(address, data);
  }
View Full Code Here

TOP

Related Classes of com.google.k2crypto.storage.StoreIOException

Copyright © 2018 www.massapicom. 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.