當前位置: 首頁>>代碼示例>>Java>>正文


Java DB.put方法代碼示例

本文整理匯總了Java中org.iq80.leveldb.DB.put方法的典型用法代碼示例。如果您正苦於以下問題:Java DB.put方法的具體用法?Java DB.put怎麽用?Java DB.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.iq80.leveldb.DB的用法示例。


在下文中一共展示了DB.put方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: submitScore

import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public static boolean submitScore(String username, String score) throws IOException {
    Options options = new Options();
    options.createIfMissing(true);
    DB db = factory.open(new File("database"), options);

    String value = asString(db.get(bytes("scores")));

    org.json.JSONObject scoreJSON;
    if (!value.isEmpty()) { //user score
        scoreJSON = new org.json.JSONObject(value);
    } else {
        scoreJSON = new org.json.JSONObject();
    }

    scoreJSON.put(username, score);

    System.out.println("All Scores: \n" + scoreJSON.toString());

    db.put(bytes("scores"), bytes(scoreJSON.toString()));
    db.close();
    return true;
}
 
開發者ID:kaloni,項目名稱:TheJavaProject,代碼行數:23,代碼來源:DatabaseHelper.java

示例2: testBadKeyIteration

import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@Test
public void testBadKeyIteration() throws Exception {
  stateStore = new LeveldbRMStateStore();
  stateStore.init(conf);
  stateStore.start();
  DB db = stateStore.getDatabase();
  // add an entry that appears at the end of the database when iterating
  db.put(JniDBFactory.bytes("zzz"), JniDBFactory.bytes("z"));
  stateStore.loadState();
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:11,代碼來源:TestLeveldbRMStateStore.java

示例3: signUp

import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public static boolean signUp(String username, String password) throws IOException {
    Options options = new Options();
    options.createIfMissing(true);
    DB db = factory.open(new File("database"), options);

    String value = asString(db.get(bytes(username)));

    if (!value.isEmpty()) { //user already registered
        return false;
    }

    db.put(bytes(username), bytes(password));
    db.close();
    return true;
}
 
開發者ID:kaloni,項目名稱:TheJavaProject,代碼行數:16,代碼來源:DatabaseHelper.java

示例4: put

import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public static <T extends D_Level> void put(String cluster, T data) throws IOException {
	DB db = getDB(path(cluster, data.getClass()));
	db.put(data.key().getBytes(), data.value(), new WriteOptions().sync(true));
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:5,代碼來源:LevelTable.java

示例5: storeVersion

import org.iq80.leveldb.DB; //導入方法依賴的package包/類
public static void storeVersion(DB db, StoreVersion version, ObjectMapper mapper)
    throws IOException {
  db.put(StoreVersion.KEY, mapper.writeValueAsBytes(version));
}
 
開發者ID:spafka,項目名稱:spark_deep,代碼行數:5,代碼來源:LevelDBProvider.java

示例6: createPreviewEntryFromExistDBFile

import org.iq80.leveldb.DB; //導入方法依賴的package包/類
@SuppressWarnings("SleepWhileInLoop")
public static Image createPreviewEntryFromExistDBFile(byte[] md5b, XImg.PreviewType type) throws IOException, InterruptedException {
    if (XImg.getPSizes().getPrimaryPreviewSize() == null) {
        throw new IOException("Preview default size is not set.");
    }
            
    final String filePath = getPathString(md5b);
    final Path path = FileSystems.getDefault().getPath(filePath);
    
    final byte[] fileCC = Files.readAllBytes(path);
    final byte[] decryptedCC = XImg.getCrypt().decrypt(fileCC);

    final XImgSimpleImageInfo xi = new XImgSimpleImageInfo(decryptedCC);
    final int rawSize = (xi.getHeight() * xi.getWidth() * 4);
    BufferedImage image2;
    if (rawSize > FILE_SIZE_LIMIT_RAW) {
        logger.error("File raw size too big. Compressed:"+decryptedCC.length+" / RAW:"+rawSize+"; limit RAW:"+FILE_SIZE_LIMIT_RAW);
        image2 = SwingFXUtils.fromFXImage(tooBigImage, null);
    } else {
        try {
            image2 = ImageIO.read(new ByteArrayInputStream(decryptedCC));
        } catch (Exception e) {
            image2 = SwingFXUtils.fromFXImage(brokenImage, null);
        }
    }
    
    synchronized (imgConv) {
        imgConv.setPreviewSize((int) XImg.getPSizes().getPrimaryPreviewSize().getWidth(), 
                (int) XImg.getPSizes().getPrimaryPreviewSize().getHeight(), XImg.getPSizes().getPrimaryPreviewSize().isSquared());
    }
    final byte[] image = imgConv.getPreviewFS(image2);
    
    mediaTracker.removeImage(image2);
    
    final byte previewCrypted[] = XImg.getCrypt().crypt(image);
    final XImgPreviewGen.PreviewElement peDB = new XImgPreviewGen.PreviewElement();
    peDB.setMD5(md5b);
    peDB.setCryptedImageBytes(previewCrypted, XImg.getPSizes().getPrimaryPreviewSize().getPrevName());

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(peDB);
    oos.flush();
    
    final byte[] crypted = XImg.getCrypt().crypt(baos.toByteArray());
    if (crypted == null) return null; //throw new IOException("Crypt() return null;");
    
    final DB db = XImg.getDB(type);
    synchronized (db) {
        db.put(md5b, crypted);
    }
    
    oos.close();
    baos.close();
    
    return new Image(new ByteArrayInputStream(image));
}
 
開發者ID:konachan700,項目名稱:JNekoImageDB,代碼行數:58,代碼來源:XImgDatastore.java


注:本文中的org.iq80.leveldb.DB.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。