亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? valuelob.java

?? 非常棒的java數(shù)據(jù)庫
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
 * (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */
package org.h2.value;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.h2.constant.SysProperties;
import org.h2.engine.Constants;
import org.h2.message.Message;
import org.h2.store.DataHandler;
import org.h2.store.FileStore;
import org.h2.store.FileStoreInputStream;
import org.h2.store.FileStoreOutputStream;
import org.h2.store.fs.FileSystem;
import org.h2.util.ByteUtils;
import org.h2.util.FileUtils;
import org.h2.util.IOUtils;
import org.h2.util.MathUtils;
import org.h2.util.SmallLRUCache;
import org.h2.util.StringUtils;

/**
 * Implementation of the BLOB and CLOB data types.
 */
public class ValueLob extends Value {
    // TODO lob: concatenate function for blob and clob 
    // (to create a large blob from pieces)
    // and a getpart function (to get it in pieces) and make sure a file is created!

    public static final int TABLE_ID_SESSION = -1;

    private final int type;
    private long precision;
    private DataHandler handler;
    private int tableId;
    private int objectId;
    private String fileName;
    private boolean linked;
    private byte[] small;
    private int hash;
    private boolean compression;
    private FileStore tempFile;

    /**
     * This counter is used to calculate the next directory to store lobs.
     * It is better than using a random number because less directories are created.
     */
    private static int dirCounter;

    private ValueLob(int type, DataHandler handler, String fileName, int tableId, int objectId, boolean linked,
            long precision, boolean compression) {
        this.type = type;
        this.handler = handler;
        this.fileName = fileName;
        this.tableId = tableId;
        this.objectId = objectId;
        this.linked = linked;
        this.precision = precision;
        this.compression = compression;
    }

    private static ValueLob copy(ValueLob lob) {
        ValueLob copy = new ValueLob(lob.type, lob.handler, lob.fileName, lob.tableId, lob.objectId, lob.linked, lob.precision, lob.compression);
        copy.small = lob.small;
        copy.hash = lob.hash;
        return copy;
    }

    private ValueLob(int type, byte[] small) throws SQLException {
        this.type = type;
        this.small = small;
        if (small != null) {
            if (type == Value.BLOB) {
                this.precision = small.length;
            } else {
                this.precision = getString().length();
            }
        }
    }

    public static ValueLob createSmallLob(int type, byte[] small) throws SQLException {
        return new ValueLob(type, small);
    }

    private static String getFileName(DataHandler handler, int tableId, int objectId) {
        if (SysProperties.CHECK && tableId == 0 && objectId == 0) {
            throw Message.getInternalError("0 LOB");
        }
        if (handler.getLobFilesInDirectories()) {
            String table = tableId < 0 ? ".temp" : ".t" + tableId;
            return getFileNamePrefix(handler.getDatabasePath(), objectId) + table + Constants.SUFFIX_LOB_FILE;
        } else {
            return handler.getDatabasePath() + "." + tableId + "." + objectId + Constants.SUFFIX_LOB_FILE;
        }
    }

    /**
     * Create a LOB value with the given parameters.
     * 
     * @param type the data type
     * @param handler the file handler
     * @param tableId the table object id
     * @param objectId the object id
     * @param precision the precision (length in elements)
     * @param compression if compression is used
     * @return the value object
     */
    public static ValueLob open(int type, DataHandler handler, int tableId, int objectId, long precision, boolean compression) {
        String fileName = getFileName(handler, tableId, objectId);
        return new ValueLob(type, handler, fileName, tableId, objectId, true, precision, compression);
    }

    public static ValueLob createClob(Reader in, long length, DataHandler handler) throws SQLException {
        try {
            boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
            long remaining = Long.MAX_VALUE;
            if (length >= 0 && length < remaining) {
                remaining = length;
            }
            int len = getBufferSize(handler, compress, remaining);
            char[] buff = new char[len];
            len = IOUtils.readFully(in, buff, len);
            len = len < 0 ? 0 : len;
            if (len <= handler.getMaxLengthInplaceLob()) {
                byte[] small = StringUtils.utf8Encode(new String(buff, 0, len));
                return ValueLob.createSmallLob(Value.CLOB, small);
            }
            ValueLob lob = new ValueLob(Value.CLOB, null);
            lob.createFromReader(buff, len, in, remaining, handler);
            return lob;
        } catch (IOException e) {
            throw Message.convertIOException(e, null);
        }
    }

    private static int getBufferSize(DataHandler handler, boolean compress, long remaining) {
        if (remaining < 0 || remaining > Integer.MAX_VALUE) {
            remaining = Integer.MAX_VALUE;
        }
        long inplace = handler.getMaxLengthInplaceLob();
        if (inplace >= Integer.MAX_VALUE) {
           inplace = remaining;
        }
        long m = compress ? Constants.IO_BUFFER_SIZE_COMPRESS : Constants.IO_BUFFER_SIZE;
        if (m < remaining && m <= inplace) {
            m = Math.min(remaining, inplace + 1);
            // the buffer size must be bigger than the inplace lob, otherwise we can't
            // know if it must be stored in-place or not
            m = MathUtils.roundUpLong(m, Constants.IO_BUFFER_SIZE);
        }
        m = Math.min(remaining, m);
        m = MathUtils.convertLongToInt(m);
        if (m < 0) {
            m = Integer.MAX_VALUE;
        }
        return (int) m;
    }

    private void createFromReader(char[] buff, int len, Reader in, long remaining, DataHandler handler) throws SQLException {
        try {
            FileStoreOutputStream out = initLarge(handler);
            boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
            try {
                while (true) {
                    precision += len;
                    byte[] b = StringUtils.utf8Encode(new String(buff, 0, len));
                    out.write(b, 0, b.length);
                    remaining -= len;
                    if (remaining <= 0) {
                        break;
                    }
                    len = getBufferSize(handler, compress, remaining);
                    len = IOUtils.readFully(in, buff, len);
                    if (len <= 0) {
                        break;
                    }
                }
            } finally {
                out.close();
            }
        } catch (IOException e) {
            throw Message.convertIOException(e, null);
        }
    }

    private static String getFileNamePrefix(String path, int objectId) {
        String name;
        int f = objectId % SysProperties.LOB_FILES_PER_DIRECTORY;
        if (f > 0) {
            name = File.separator + objectId;
        } else {
            name = "";
        }
        objectId /= SysProperties.LOB_FILES_PER_DIRECTORY;
        while (objectId > 0) {
            f = objectId % SysProperties.LOB_FILES_PER_DIRECTORY;
            name = File.separator + f + Constants.SUFFIX_LOBS_DIRECTORY + name;
            objectId /= SysProperties.LOB_FILES_PER_DIRECTORY;
        }
        name = path + Constants.SUFFIX_LOBS_DIRECTORY + name;
        return name;
    }

    private int getNewObjectId(DataHandler handler) throws SQLException {
        String path = handler.getDatabasePath();
        int objectId = 0;
        while (true) {
            String dir = getFileNamePrefix(path, objectId);
            String[] list = getFileList(handler, dir);
            int fileCount = 0;
            boolean[] used = new boolean[SysProperties.LOB_FILES_PER_DIRECTORY];
            for (int i = 0; i < list.length; i++) {
                String name = list[i];
                if (name.endsWith(Constants.SUFFIX_DB_FILE)) {
                    name = name.substring(name.lastIndexOf(File.separatorChar) + 1);
                    String n = name.substring(0, name.indexOf('.'));
                    int id;
                    try {
                        id = Integer.parseInt(n);
                    } catch (NumberFormatException e) {
                        id = -1;
                    }
                    if (id > 0) {
                        fileCount++;
                        used[id % SysProperties.LOB_FILES_PER_DIRECTORY] = true;
                    }
                }
            }
            int fileId = -1;
            if (fileCount < SysProperties.LOB_FILES_PER_DIRECTORY) {
                for (int i = 1; i < SysProperties.LOB_FILES_PER_DIRECTORY; i++) {
                    if (!used[i]) {
                        fileId = i;
                        break;
                    }
                }
            }
            if (fileId > 0) {
                objectId += fileId;
                invalidateFileList(handler, dir);
                break;
            } else {
                if (objectId > Integer.MAX_VALUE / SysProperties.LOB_FILES_PER_DIRECTORY) {
                    // this directory path is full: start from zero
                    // (this can happen only theoretically, 
                    // for example if the random number generator is broken)
                    objectId = 0;
                } else {
                    // calculate the directory
                    // start with 1 (otherwise we don't know the number of directories)
                    // it doesn't really matter what directory is used, it might as well be random
                    // (but that would generate more directories):
                    // int dirId = RandomUtils.nextInt(
                    //         SysProperties.LOB_FILES_PER_DIRECTORY - 1) + 1;
                    int dirId = (dirCounter++ / (SysProperties.LOB_FILES_PER_DIRECTORY - 1)) + 1;
                    objectId = objectId * SysProperties.LOB_FILES_PER_DIRECTORY;
                    objectId += dirId * SysProperties.LOB_FILES_PER_DIRECTORY;
                }
            }
        }
        return objectId;
    }

    private void invalidateFileList(DataHandler handler, String dir) {
        SmallLRUCache cache = handler.getLobFileListCache();
        if (cache != null) {
            synchronized (cache) {
                cache.remove(dir);
            }
        }
    }

    private String[] getFileList(DataHandler handler, String dir) throws SQLException {
        SmallLRUCache cache = handler.getLobFileListCache();
        String[] list;
        if (cache == null) {
            list = FileUtils.listFiles(dir);
        } else {
            synchronized (cache) {
                list = (String[]) cache.get(dir);
                if (list == null) {
                    list = FileUtils.listFiles(dir);
                    cache.put(dir, list);
                }
            }
        }
        return list;
    }

    public static ValueLob createBlob(InputStream in, long length, DataHandler handler) throws SQLException {
        try {
            long remaining = Long.MAX_VALUE;
            boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null;
            if (length >= 0 && length < remaining) {
                remaining = length;
            }
            int len = getBufferSize(handler, compress, remaining);
            byte[] buff = new byte[len];
            len = IOUtils.readFully(in, buff, 0, len);
            if (len <= handler.getMaxLengthInplaceLob()) {
                byte[] small = new byte[len];
                System.arraycopy(buff, 0, small, 0, len);
                return ValueLob.createSmallLob(Value.BLOB, small);
            }
            ValueLob lob = new ValueLob(Value.BLOB, null);
            lob.createFromStream(buff, len, in, remaining, handler);
            return lob;
        } catch (IOException e) {
            throw Message.convertIOException(e, null);
        }
    }

    private FileStoreOutputStream initLarge(DataHandler handler) throws IOException, SQLException {
        this.handler = handler;
        this.tableId = 0;
        this.linked = false;
        this.precision = 0;
        this.small = null;
        this.hash = 0;
        String compressionAlgorithm = handler.getLobCompressionAlgorithm(type);
        this.compression = compressionAlgorithm != null;
        synchronized (handler) {
            if (handler.getLobFilesInDirectories()) {
                objectId = getNewObjectId(handler);
                fileName = getFileNamePrefix(handler.getDatabasePath(), objectId) + ".temp.db";
            } else {
                objectId = handler.allocateObjectId(false, true);
                fileName = handler.createTempFile();
            }
            tempFile = handler.openFile(fileName, "rw", false);
            tempFile.autoDelete();
        }
        FileStoreOutputStream out = new FileStoreOutputStream(tempFile, handler, compressionAlgorithm);
        return out;
    }

    private void createFromStream(byte[] buff, int len, InputStream in, long remaining, DataHandler handler)
            throws SQLException {
        try {
            FileStoreOutputStream out = initLarge(handler);
            boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null;
            try {
                while (true) {
                    precision += len;
                    out.write(buff, 0, len);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
中文字幕av资源一区| 全国精品久久少妇| 日本不卡高清视频| 91麻豆免费看片| 日韩精品在线一区| 亚洲电影在线免费观看| 成人天堂资源www在线| 日韩午夜小视频| 一区二区三区精品在线| 国产91丝袜在线18| 精品美女被调教视频大全网站| 亚洲色欲色欲www| 国产成人精品三级| 精品久久久久av影院| 亚洲chinese男男1069| 99精品久久免费看蜜臀剧情介绍| 欧美成人免费网站| 日本美女视频一区二区| 欧美日韩亚洲综合在线| 一区二区三区免费网站| 99久久精品国产精品久久| 久久久精品综合| 激情伊人五月天久久综合| 日韩一区二区麻豆国产| 天天操天天综合网| 欧美久久免费观看| 亚洲成人av一区二区| 欧美性视频一区二区三区| 亚洲人成精品久久久久久| av亚洲产国偷v产偷v自拍| 国产精品视频一区二区三区不卡| 国内成人精品2018免费看| 欧美一区二区三区免费| 蜜臀av国产精品久久久久 | 国内欧美视频一区二区| 91精品国产麻豆| 免费人成网站在线观看欧美高清| 欧美久久久影院| 蜜桃久久久久久久| 久久久蜜臀国产一区二区| 国产精品综合二区| 国产精品久久久久久一区二区三区| 国产成人午夜精品5599| 中文字幕成人av| 91蝌蚪porny九色| 亚洲综合小说图片| 欧美老年两性高潮| 另类小说综合欧美亚洲| 久久九九99视频| 99re热视频这里只精品| 亚洲综合丝袜美腿| 欧美精品乱码久久久久久 | 7777精品伊人久久久大香线蕉超级流畅| 亚洲精品老司机| 3atv一区二区三区| 国内精品在线播放| 中文字幕一区二区三区视频| 色综合av在线| 美美哒免费高清在线观看视频一区二区 | 一区二区三区视频在线看| 欧美三级在线播放| 韩国三级电影一区二区| 国产精品另类一区| 欧美日韩视频在线观看一区二区三区| 蜜桃久久久久久| 中文字幕一区在线| 欧美色爱综合网| 国产成人鲁色资源国产91色综| 亚洲免费av观看| 精品欧美一区二区三区精品久久| 成人美女视频在线观看| 91蜜桃婷婷狠狠久久综合9色| 国产亚洲欧美色| 色噜噜久久综合| 精品一区中文字幕| 欧美大片一区二区| 成人av网站免费| 手机精品视频在线观看| 国产欧美一区视频| 精品污污网站免费看| 国产美女在线精品| 成人动漫一区二区三区| 日韩亚洲欧美一区二区三区| 日本少妇一区二区| 欧美一区欧美二区| 国产一区二区0| 久久久不卡影院| 国产69精品久久久久毛片 | 日本在线不卡一区| 日韩一区二区免费视频| 九九精品一区二区| 国产欧美精品一区二区三区四区| 国产精品456| 亚洲欧美激情一区二区| 在线精品观看国产| 午夜不卡av免费| 精品国精品国产| 国产寡妇亲子伦一区二区| 国产精品久久久一本精品| 91视频国产资源| 丝瓜av网站精品一区二区| 日韩欧美高清一区| 99久久精品情趣| 午夜精品福利一区二区三区av| 91精品国产综合久久久久| 久久www免费人成看片高清| 中文字幕欧美三区| 欧美日韩亚洲综合在线 欧美亚洲特黄一级| 五月天一区二区| 国产拍揄自揄精品视频麻豆| 在线亚洲免费视频| 国产一区二区三区在线观看免费 | 欧美色图免费看| 久久99精品国产麻豆婷婷| 国产精品国产自产拍高清av王其| 欧美亚洲免费在线一区| 国产盗摄一区二区| 午夜精品在线看| 日本一区二区三区四区| 欧美日韩一区二区在线视频| 国产成人综合亚洲91猫咪| 亚洲国产精品一区二区久久 | 欧美亚一区二区| 国产馆精品极品| 日韩电影一区二区三区| 亚洲欧洲日韩在线| 欧美成人福利视频| 91久久久免费一区二区| 国产精品亚洲第一| 日韩av一二三| 亚洲综合视频在线| 国产精品久久夜| 懂色中文一区二区在线播放| 日韩不卡在线观看日韩不卡视频| 国产精品久久久久婷婷二区次| 日韩一区二区中文字幕| 一本色道久久综合亚洲aⅴ蜜桃 | 91福利视频久久久久| 国产又黄又大久久| 免费观看日韩电影| 五月婷婷综合网| 亚洲成人一二三| 夜色激情一区二区| 亚洲色图一区二区| 国产精品日韩精品欧美在线| 精品88久久久久88久久久| 制服丝袜国产精品| 欧美日韩免费观看一区三区| 日本精品一区二区三区高清| 97久久超碰国产精品| 99麻豆久久久国产精品免费优播| 国产99一区视频免费| 国产99一区视频免费| 国产精品1024| 国产99久久久久| 成人免费看黄yyy456| 暴力调教一区二区三区| 99精品欧美一区二区三区综合在线| 国产成人在线网站| 本田岬高潮一区二区三区| jiyouzz国产精品久久| 不卡的电影网站| 色婷婷一区二区| 欧美偷拍一区二区| 91精品国产色综合久久不卡电影| 欧美美女网站色| 日韩欧美中文字幕精品| 欧美成人欧美edvon| 久久久久97国产精华液好用吗| 久久久久久久精| 亚洲人一二三区| 午夜视频一区二区三区| 麻豆国产精品777777在线| 国产一区二区三区久久悠悠色av| 丁香婷婷综合色啪| 在线日韩一区二区| 日韩午夜av一区| 亚洲www啪成人一区二区麻豆| 亚洲成人av一区二区三区| 日韩高清一区在线| 成人性生交大片免费看视频在线| 91在线无精精品入口| 91.com视频| 欧美国产日韩a欧美在线观看| 亚洲精品国产品国语在线app| 亚洲在线视频一区| 国产一区二区剧情av在线| 91影视在线播放| 欧美成人福利视频| 亚洲另类中文字| 激情丁香综合五月| 91成人网在线| 久久亚洲综合色一区二区三区| 国产精品免费观看视频| 性欧美大战久久久久久久久| 国产黄色精品视频| 欧美二区在线观看| 亚洲免费观看视频| 国产美女在线精品| 8v天堂国产在线一区二区|