Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5e8bd060
提交
5e8bd060
authored
3月 12, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move newBytes() and copyBytes() to Utils
上级
dda78956
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
103 行增加
和
109 行删除
+103
-109
LZFInputStream.java
h2/src/main/org/h2/compress/LZFInputStream.java
+2
-2
Function.java
h2/src/main/org/h2/expression/Function.java
+1
-2
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+0
-61
MVStoreTool.java
h2/src/main/org/h2/mvstore/MVStoreTool.java
+2
-1
Page.java
h2/src/main/org/h2/mvstore/Page.java
+2
-1
ValueDataType.java
h2/src/main/org/h2/mvstore/db/ValueDataType.java
+8
-7
ObjectDataType.java
h2/src/main/org/h2/mvstore/type/ObjectDataType.java
+5
-4
PgServerThread.java
h2/src/main/org/h2/server/pg/PgServerThread.java
+4
-5
WebThread.java
h2/src/main/org/h2/server/web/WebThread.java
+2
-2
Data.java
h2/src/main/org/h2/store/Data.java
+8
-8
FileStoreInputStream.java
h2/src/main/org/h2/store/FileStoreInputStream.java
+2
-2
CompressTool.java
h2/src/main/org/h2/tools/CompressTool.java
+5
-5
Utils.java
h2/src/main/org/h2/util/Utils.java
+56
-0
Transfer.java
h2/src/main/org/h2/value/Transfer.java
+1
-2
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+3
-4
ValueLobDb.java
h2/src/main/org/h2/value/ValueLobDb.java
+2
-3
没有找到文件。
h2/src/main/org/h2/compress/LZFInputStream.java
浏览文件 @
5e8bd060
...
...
@@ -8,7 +8,7 @@ package org.h2.compress;
import
java.io.IOException
;
import
java.io.InputStream
;
import
org.h2.message.DbException
;
import
org.h2.
mvstore.Data
Utils
;
import
org.h2.
util.
Utils
;
/**
* An input stream to read from an LZF stream.
...
...
@@ -31,7 +31,7 @@ public class LZFInputStream extends InputStream {
}
private
static
byte
[]
ensureSize
(
byte
[]
buff
,
int
len
)
{
return
buff
==
null
||
buff
.
length
<
len
?
Data
Utils
.
newBytes
(
len
)
:
buff
;
return
buff
==
null
||
buff
.
length
<
len
?
Utils
.
newBytes
(
len
)
:
buff
;
}
private
void
fillBuffer
()
throws
IOException
{
...
...
h2/src/main/org/h2/expression/Function.java
浏览文件 @
5e8bd060
...
...
@@ -31,7 +31,6 @@ import org.h2.engine.Database;
import
org.h2.engine.Mode
;
import
org.h2.engine.Session
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.schema.Schema
;
import
org.h2.schema.Sequence
;
import
org.h2.security.BlockCipher
;
...
...
@@ -1819,7 +1818,7 @@ public class Function extends Expression implements FunctionCall {
private
static
byte
[]
getPaddedArrayCopy
(
byte
[]
data
,
int
blockSize
)
{
int
size
=
MathUtils
.
roundUpInt
(
data
.
length
,
blockSize
);
return
Data
Utils
.
copyBytes
(
data
,
size
);
return
Utils
.
copyBytes
(
data
,
size
);
}
private
static
byte
[]
decrypt
(
String
algorithm
,
byte
[]
key
,
byte
[]
data
)
{
...
...
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
5e8bd060
...
...
@@ -153,11 +153,6 @@ public final class DataUtils {
*/
public
static
final
int
PAGE_LARGE
=
2
*
1024
*
1024
;
/**
* An 0-size byte array.
*/
private
static
final
byte
[]
EMPTY_BYTES
=
{};
/**
* Get the length of the variable size int.
*
...
...
@@ -937,62 +932,6 @@ public final class DataUtils {
return
0
;
}
/**
* Create an array of bytes with the given size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
* <p>
* This method should be used if the size of the array is user defined, or
* stored in a file, so wrong size data can be distinguished from regular
* out-of-memory.
* </p>
*
* @param len the number of bytes requested
* @return the byte array
* @throws OutOfMemoryError if the allocation was too large
*/
public
static
byte
[]
newBytes
(
int
len
)
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
}
try
{
return
new
byte
[
len
];
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
/**
* Creates a copy of array of bytes with the new size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
* <p>
* This method should be used if the size of the array is user defined, or
* stored in a file, so wrong size data can be distinguished from regular
* out-of-memory.
* </p>
*
* @param bytes source array
* @param len the number of bytes in the new array
* @return the byte array
* @throws OutOfMemoryError if the allocation was too large
* @see Arrays#copyOf(byte[], int)
*/
public
static
byte
[]
copyBytes
(
byte
[]
bytes
,
int
len
)
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
}
try
{
return
Arrays
.
copyOf
(
bytes
,
len
);
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
/**
* Read a hex long value from a map.
*
...
...
h2/src/main/org/h2/mvstore/MVStoreTool.java
浏览文件 @
5e8bd060
...
...
@@ -26,6 +26,7 @@ import org.h2.mvstore.type.DataType;
import
org.h2.mvstore.type.StringDataType
;
import
org.h2.store.fs.FilePath
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.util.Utils
;
/**
* Utility methods used in combination with the MVStore.
...
...
@@ -226,7 +227,7 @@ public class MVStoreTool {
Compressor
compressor
=
getCompressor
(
fast
);
int
lenAdd
=
DataUtils
.
readVarInt
(
chunk
);
int
compLen
=
pageSize
+
start
-
chunk
.
position
();
byte
[]
comp
=
Data
Utils
.
newBytes
(
compLen
);
byte
[]
comp
=
Utils
.
newBytes
(
compLen
);
chunk
.
get
(
comp
);
int
l
=
compLen
+
lenAdd
;
data
=
ByteBuffer
.
allocate
(
l
);
...
...
h2/src/main/org/h2/mvstore/Page.java
浏览文件 @
5e8bd060
...
...
@@ -9,6 +9,7 @@ import java.nio.ByteBuffer;
import
java.util.HashSet
;
import
org.h2.compress.Compressor
;
import
org.h2.mvstore.type.DataType
;
import
org.h2.util.Utils
;
/**
* A page (a node or a leaf).
...
...
@@ -702,7 +703,7 @@ public class Page {
}
int
lenAdd
=
DataUtils
.
readVarInt
(
buff
);
int
compLen
=
pageLength
+
start
-
buff
.
position
();
byte
[]
comp
=
Data
Utils
.
newBytes
(
compLen
);
byte
[]
comp
=
Utils
.
newBytes
(
compLen
);
buff
.
get
(
comp
);
int
l
=
compLen
+
lenAdd
;
buff
=
ByteBuffer
.
allocate
(
l
);
...
...
h2/src/main/org/h2/mvstore/db/ValueDataType.java
浏览文件 @
5e8bd060
...
...
@@ -23,6 +23,7 @@ import org.h2.result.SortOrder;
import
org.h2.store.DataHandler
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.Utils
;
import
org.h2.value.CompareMode
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -489,7 +490,7 @@ public class ValueDataType implements DataType {
case
Value
.
DECIMAL
:
{
int
scale
=
readVarInt
(
buff
);
int
len
=
readVarInt
(
buff
);
byte
[]
buff2
=
Data
Utils
.
newBytes
(
len
);
byte
[]
buff2
=
Utils
.
newBytes
(
len
);
buff
.
get
(
buff2
,
0
,
len
);
BigInteger
b
=
new
BigInteger
(
buff2
);
return
ValueDecimal
.
get
(
new
BigDecimal
(
b
,
scale
));
...
...
@@ -514,13 +515,13 @@ public class ValueDataType implements DataType {
}
case
Value
.
BYTES
:
{
int
len
=
readVarInt
(
buff
);
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
buff
.
get
(
b
,
0
,
len
);
return
ValueBytes
.
getNoCopy
(
b
);
}
case
Value
.
JAVA_OBJECT
:
{
int
len
=
readVarInt
(
buff
);
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
buff
.
get
(
b
,
0
,
len
);
return
ValueJavaObject
.
getNoCopy
(
null
,
b
,
handler
);
}
...
...
@@ -550,7 +551,7 @@ public class ValueDataType implements DataType {
case
Value
.
CLOB
:
{
int
smallLen
=
readVarInt
(
buff
);
if
(
smallLen
>=
0
)
{
byte
[]
small
=
Data
Utils
.
newBytes
(
smallLen
);
byte
[]
small
=
Utils
.
newBytes
(
smallLen
);
buff
.
get
(
small
,
0
,
smallLen
);
return
ValueLobDb
.
createSmallLob
(
type
,
small
);
}
else
if
(
smallLen
==
-
3
)
{
...
...
@@ -597,7 +598,7 @@ public class ValueDataType implements DataType {
}
case
Value
.
GEOMETRY
:
{
int
len
=
readVarInt
(
buff
);
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
buff
.
get
(
b
,
0
,
len
);
return
ValueGeometry
.
get
(
b
);
}
...
...
@@ -607,7 +608,7 @@ public class ValueDataType implements DataType {
if
(
JdbcUtils
.
customDataTypesHandler
!=
null
)
{
int
customType
=
readVarInt
(
buff
);
int
len
=
readVarInt
(
buff
);
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
buff
.
get
(
b
,
0
,
len
);
return
JdbcUtils
.
customDataTypesHandler
.
convert
(
ValueBytes
.
getNoCopy
(
b
),
customType
);
...
...
@@ -622,7 +623,7 @@ public class ValueDataType implements DataType {
return
ValueLong
.
get
(
type
-
LONG_0_7
);
}
else
if
(
type
>=
BYTES_0_31
&&
type
<
BYTES_0_31
+
32
)
{
int
len
=
type
-
BYTES_0_31
;
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
buff
.
get
(
b
,
0
,
len
);
return
ValueBytes
.
getNoCopy
(
b
);
}
else
if
(
type
>=
STRING_0_31
&&
type
<
STRING_0_31
+
32
)
{
...
...
h2/src/main/org/h2/mvstore/type/ObjectDataType.java
浏览文件 @
5e8bd060
...
...
@@ -19,6 +19,7 @@ import java.util.HashMap;
import
java.util.UUID
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.mvstore.WriteBuffer
;
import
org.h2.util.Utils
;
/**
* A data type implementation for the most common data types, including
...
...
@@ -1000,7 +1001,7 @@ public class ObjectDataType implements DataType {
return
BigInteger
.
valueOf
(
DataUtils
.
readVarLong
(
buff
));
}
int
len
=
DataUtils
.
readVarInt
(
buff
);
byte
[]
bytes
=
Data
Utils
.
newBytes
(
len
);
byte
[]
bytes
=
Utils
.
newBytes
(
len
);
buff
.
get
(
bytes
);
return
new
BigInteger
(
bytes
);
}
...
...
@@ -1077,7 +1078,7 @@ public class ObjectDataType implements DataType {
}
int
scale
=
DataUtils
.
readVarInt
(
buff
);
int
len
=
DataUtils
.
readVarInt
(
buff
);
byte
[]
bytes
=
Data
Utils
.
newBytes
(
len
);
byte
[]
bytes
=
Utils
.
newBytes
(
len
);
buff
.
get
(
bytes
);
BigInteger
b
=
new
BigInteger
(
bytes
);
return
new
BigDecimal
(
b
,
scale
);
...
...
@@ -1414,7 +1415,7 @@ public class ObjectDataType implements DataType {
if
(
tag
!=
TYPE_ARRAY
)
{
byte
[]
data
;
int
len
=
tag
-
TAG_BYTE_ARRAY_0_15
;
data
=
Data
Utils
.
newBytes
(
len
);
data
=
Utils
.
newBytes
(
len
);
buff
.
get
(
data
);
return
data
;
}
...
...
@@ -1545,7 +1546,7 @@ public class ObjectDataType implements DataType {
@Override
public
Object
read
(
ByteBuffer
buff
,
int
tag
)
{
int
len
=
DataUtils
.
readVarInt
(
buff
);
byte
[]
data
=
Data
Utils
.
newBytes
(
len
);
byte
[]
data
=
Utils
.
newBytes
(
len
);
int
size
=
data
.
length
*
2
;
// adjust the average size
// using an exponential moving average
...
...
h2/src/main/org/h2/server/pg/PgServerThread.java
浏览文件 @
5e8bd060
...
...
@@ -40,7 +40,6 @@ import org.h2.jdbc.JdbcPreparedStatement;
import
org.h2.jdbc.JdbcResultSet
;
import
org.h2.jdbc.JdbcStatement
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.MathUtils
;
...
...
@@ -152,7 +151,7 @@ public class PgServerThread implements Runnable {
}
int
len
=
dataInRaw
.
readInt
();
len
-=
4
;
byte
[]
data
=
Data
Utils
.
newBytes
(
len
);
byte
[]
data
=
Utils
.
newBytes
(
len
);
dataInRaw
.
readFully
(
data
,
0
,
len
);
dataIn
=
new
DataInputStream
(
new
ByteArrayInputStream
(
data
,
0
,
len
));
switch
(
x
)
{
...
...
@@ -639,7 +638,7 @@ public class PgServerThread implements Runnable {
prep
.
setNull
(
col
,
Types
.
NULL
);
}
else
if
(
text
)
{
// plain text
byte
[]
data
=
Data
Utils
.
newBytes
(
paramLen
);
byte
[]
data
=
Utils
.
newBytes
(
paramLen
);
readFully
(
data
);
String
str
=
new
String
(
data
,
getEncoding
());
switch
(
pgType
)
{
...
...
@@ -687,13 +686,13 @@ public class PgServerThread implements Runnable {
prep
.
setDouble
(
col
,
dataIn
.
readDouble
());
break
;
case
PgServer
.
PG_TYPE_BYTEA
:
byte
[]
d1
=
Data
Utils
.
newBytes
(
paramLen
);
byte
[]
d1
=
Utils
.
newBytes
(
paramLen
);
readFully
(
d1
);
prep
.
setBytes
(
col
,
d1
);
break
;
default
:
server
.
trace
(
"Binary format for type: "
+
pgType
+
" is unsupported"
);
byte
[]
d2
=
Data
Utils
.
newBytes
(
paramLen
);
byte
[]
d2
=
Utils
.
newBytes
(
paramLen
);
readFully
(
d2
);
prep
.
setString
(
col
,
new
String
(
d2
,
getEncoding
()));
}
...
...
h2/src/main/org/h2/server/web/WebThread.java
浏览文件 @
5e8bd060
...
...
@@ -20,10 +20,10 @@ import java.util.StringTokenizer;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.NetUtils
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
* For each connection to a session, an object of this class is created.
...
...
@@ -317,7 +317,7 @@ class WebThread extends WebApp implements Runnable {
if
(
multipart
)
{
// not supported
}
else
if
(
session
!=
null
&&
len
>
0
)
{
byte
[]
bytes
=
Data
Utils
.
newBytes
(
len
);
byte
[]
bytes
=
Utils
.
newBytes
(
len
);
for
(
int
pos
=
0
;
pos
<
len
;)
{
pos
+=
input
.
read
(
bytes
,
pos
,
len
-
pos
);
}
...
...
h2/src/main/org/h2/store/Data.java
浏览文件 @
5e8bd060
...
...
@@ -23,11 +23,11 @@ import org.h2.api.ErrorCode;
import
org.h2.engine.Constants
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.tools.SimpleResultSet
;
import
org.h2.util.Bits
;
import
org.h2.util.DateTimeUtils
;
import
org.h2.util.MathUtils
;
import
org.h2.util.Utils
;
import
org.h2.value.DataType
;
import
org.h2.value.Value
;
import
org.h2.value.ValueArray
;
...
...
@@ -745,7 +745,7 @@ public class Data {
case
Value
.
DECIMAL
:
{
int
scale
=
readVarInt
();
int
len
=
readVarInt
();
byte
[]
buff
=
Data
Utils
.
newBytes
(
len
);
byte
[]
buff
=
Utils
.
newBytes
(
len
);
read
(
buff
,
0
,
len
);
BigInteger
b
=
new
BigInteger
(
buff
);
return
ValueDecimal
.
get
(
new
BigDecimal
(
b
,
scale
));
...
...
@@ -783,19 +783,19 @@ public class Data {
}
case
Value
.
BYTES
:
{
int
len
=
readVarInt
();
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueBytes
.
getNoCopy
(
b
);
}
case
Value
.
GEOMETRY
:
{
int
len
=
readVarInt
();
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueGeometry
.
get
(
b
);
}
case
Value
.
JAVA_OBJECT
:
{
int
len
=
readVarInt
();
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueJavaObject
.
getNoCopy
(
null
,
b
,
handler
);
}
...
...
@@ -825,7 +825,7 @@ public class Data {
case
Value
.
CLOB
:
{
int
smallLen
=
readVarInt
();
if
(
smallLen
>=
0
)
{
byte
[]
small
=
Data
Utils
.
newBytes
(
smallLen
);
byte
[]
small
=
Utils
.
newBytes
(
smallLen
);
read
(
small
,
0
,
smallLen
);
return
ValueLobDb
.
createSmallLob
(
type
,
small
);
}
else
if
(
smallLen
==
-
3
)
{
...
...
@@ -889,7 +889,7 @@ public class Data {
return
ValueLong
.
get
(
type
-
LONG_0_7
);
}
else
if
(
type
>=
BYTES_0_31
&&
type
<
BYTES_0_31
+
32
)
{
int
len
=
type
-
BYTES_0_31
;
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
read
(
b
,
0
,
len
);
return
ValueBytes
.
getNoCopy
(
b
);
}
else
if
(
type
>=
STRING_0_31
&&
type
<
STRING_0_31
+
32
)
{
...
...
@@ -1316,7 +1316,7 @@ public class Data {
private
void
expand
(
int
plus
)
{
// must copy everything, because pos could be 0 and data may be
// still required
data
=
Data
Utils
.
copyBytes
(
data
,
(
data
.
length
+
plus
)
*
2
);
data
=
Utils
.
copyBytes
(
data
,
(
data
.
length
+
plus
)
*
2
);
}
/**
...
...
h2/src/main/org/h2/store/FileStoreInputStream.java
浏览文件 @
5e8bd060
...
...
@@ -9,8 +9,8 @@ import java.io.IOException;
import
java.io.InputStream
;
import
org.h2.engine.Constants
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.tools.CompressTool
;
import
org.h2.util.Utils
;
/**
* An input stream that is backed by a file store.
...
...
@@ -117,7 +117,7 @@ public class FileStoreInputStream extends InputStream {
page
.
readInt
();
if
(
compress
!=
null
)
{
int
uncompressed
=
page
.
readInt
();
byte
[]
buff
=
Data
Utils
.
newBytes
(
remainingInBuffer
);
byte
[]
buff
=
Utils
.
newBytes
(
remainingInBuffer
);
page
.
read
(
buff
,
0
,
remainingInBuffer
);
page
.
reset
();
page
.
checkCapacity
(
uncompressed
);
...
...
h2/src/main/org/h2/tools/CompressTool.java
浏览文件 @
5e8bd060
...
...
@@ -25,9 +25,9 @@ import org.h2.compress.LZFInputStream;
import
org.h2.compress.LZFOutputStream
;
import
org.h2.engine.Constants
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.util.Bits
;
import
org.h2.util.StringUtils
;
import
org.h2.util.Utils
;
/**
* A tool to losslessly compress data, and expand the compressed data again.
...
...
@@ -44,10 +44,10 @@ public class CompressTool {
private
byte
[]
getBuffer
(
int
min
)
{
if
(
min
>
MAX_BUFFER_SIZE
)
{
return
Data
Utils
.
newBytes
(
min
);
return
Utils
.
newBytes
(
min
);
}
if
(
cachedBuffer
==
null
||
cachedBuffer
.
length
<
min
)
{
cachedBuffer
=
Data
Utils
.
newBytes
(
min
);
cachedBuffer
=
Utils
.
newBytes
(
min
);
}
return
cachedBuffer
;
}
...
...
@@ -79,7 +79,7 @@ public class CompressTool {
Compressor
compress
=
getCompressor
(
algorithm
);
byte
[]
buff
=
getBuffer
((
len
<
100
?
len
+
100
:
len
)
*
2
);
int
newLen
=
compress
(
in
,
in
.
length
,
compress
,
buff
);
return
Data
Utils
.
copyBytes
(
buff
,
newLen
);
return
Utils
.
copyBytes
(
buff
,
newLen
);
}
private
static
int
compress
(
byte
[]
in
,
int
len
,
Compressor
compress
,
...
...
@@ -108,7 +108,7 @@ public class CompressTool {
try
{
int
len
=
readVariableInt
(
in
,
1
);
int
start
=
1
+
getVariableIntLength
(
len
);
byte
[]
buff
=
Data
Utils
.
newBytes
(
len
);
byte
[]
buff
=
Utils
.
newBytes
(
len
);
compress
.
expand
(
in
,
start
,
in
.
length
-
start
,
buff
,
0
,
len
);
return
buff
;
}
catch
(
Exception
e
)
{
...
...
h2/src/main/org/h2/util/Utils.java
浏览文件 @
5e8bd060
...
...
@@ -209,6 +209,62 @@ public class Utils {
return
target
;
}
/**
* Create an array of bytes with the given size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
* <p>
* This method should be used if the size of the array is user defined, or
* stored in a file, so wrong size data can be distinguished from regular
* out-of-memory.
* </p>
*
* @param len the number of bytes requested
* @return the byte array
* @throws OutOfMemoryError if the allocation was too large
*/
public
static
byte
[]
newBytes
(
int
len
)
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
}
try
{
return
new
byte
[
len
];
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
/**
* Creates a copy of array of bytes with the new size. If this is not possible
* because not enough memory is available, an OutOfMemoryError with the
* requested size in the message is thrown.
* <p>
* This method should be used if the size of the array is user defined, or
* stored in a file, so wrong size data can be distinguished from regular
* out-of-memory.
* </p>
*
* @param bytes source array
* @param len the number of bytes in the new array
* @return the byte array
* @throws OutOfMemoryError if the allocation was too large
* @see Arrays#copyOf(byte[], int)
*/
public
static
byte
[]
copyBytes
(
byte
[]
bytes
,
int
len
)
{
if
(
len
==
0
)
{
return
EMPTY_BYTES
;
}
try
{
return
Arrays
.
copyOf
(
bytes
,
len
);
}
catch
(
OutOfMemoryError
e
)
{
Error
e2
=
new
OutOfMemoryError
(
"Requested memory: "
+
len
);
e2
.
initCause
(
e
);
throw
e2
;
}
}
/**
* Create a new byte array and copy all the data. If the size of the byte
* array is zero, the same array is returned.
...
...
h2/src/main/org/h2/value/Transfer.java
浏览文件 @
5e8bd060
...
...
@@ -22,7 +22,6 @@ import org.h2.api.ErrorCode;
import
org.h2.engine.Constants
;
import
org.h2.engine.SessionInterface
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.security.SHA256
;
import
org.h2.store.Data
;
import
org.h2.store.DataReader
;
...
...
@@ -284,7 +283,7 @@ public class Transfer {
if
(
len
==
-
1
)
{
return
null
;
}
byte
[]
b
=
Data
Utils
.
newBytes
(
len
);
byte
[]
b
=
Utils
.
newBytes
(
len
);
in
.
readFully
(
b
);
return
b
;
}
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
5e8bd060
...
...
@@ -19,7 +19,6 @@ import org.h2.engine.Constants;
import
org.h2.engine.Mode
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.store.DataHandler
;
import
org.h2.store.FileStore
;
import
org.h2.store.FileStoreInputStream
;
...
...
@@ -430,11 +429,11 @@ public class ValueLob extends Value {
buff
=
IOUtils
.
readBytesAndClose
(
in
,
-
1
);
len
=
buff
.
length
;
}
else
{
buff
=
Data
Utils
.
newBytes
(
len
);
buff
=
Utils
.
newBytes
(
len
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
}
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
byte
[]
small
=
Data
Utils
.
copyBytes
(
buff
,
len
);
byte
[]
small
=
Utils
.
copyBytes
(
buff
,
len
);
return
ValueLob
.
createSmallLob
(
Value
.
BLOB
,
small
);
}
ValueLob
lob
=
new
ValueLob
(
Value
.
BLOB
,
null
);
...
...
@@ -796,7 +795,7 @@ public class ValueLob extends Value {
int
tabId
=
tableId
;
if
(
type
==
Value
.
BLOB
)
{
createFromStream
(
Data
Utils
.
newBytes
(
len
),
0
,
getInputStream
(),
Long
.
MAX_VALUE
,
h
);
Utils
.
newBytes
(
len
),
0
,
getInputStream
(),
Long
.
MAX_VALUE
,
h
);
}
else
{
createFromReader
(
new
char
[
len
],
0
,
getReader
(),
Long
.
MAX_VALUE
,
h
);
...
...
h2/src/main/org/h2/value/ValueLobDb.java
浏览文件 @
5e8bd060
...
...
@@ -19,7 +19,6 @@ import org.h2.engine.Constants;
import
org.h2.engine.Mode
;
import
org.h2.engine.SysProperties
;
import
org.h2.message.DbException
;
import
org.h2.mvstore.DataUtils
;
import
org.h2.store.DataHandler
;
import
org.h2.store.FileStore
;
import
org.h2.store.FileStoreInputStream
;
...
...
@@ -611,11 +610,11 @@ public class ValueLobDb extends Value implements Value.ValueClob,
buff
=
IOUtils
.
readBytesAndClose
(
in
,
-
1
);
len
=
buff
.
length
;
}
else
{
buff
=
Data
Utils
.
newBytes
(
len
);
buff
=
Utils
.
newBytes
(
len
);
len
=
IOUtils
.
readFully
(
in
,
buff
,
len
);
}
if
(
len
<=
handler
.
getMaxLengthInplaceLob
())
{
byte
[]
small
=
Data
Utils
.
copyBytes
(
buff
,
len
);
byte
[]
small
=
Utils
.
copyBytes
(
buff
,
len
);
return
ValueLobDb
.
createSmallLob
(
Value
.
BLOB
,
small
,
small
.
length
);
}
ValueLobDb
lob
=
new
ValueLobDb
(
handler
,
buff
,
len
,
in
,
remaining
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论