Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80376938
RiakUtils.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 31, 10:16
Size
2 KB
Mime Type
text/x-java
Expires
Mon, Sep 2, 10:16 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20351067
Attached To
R7507 YCSB
RiakUtils.java
View Options
/*
* Copyright 2016 nygard_89
* Copyright 2014 Basho Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.yahoo.ycsb.db
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.Map
;
import
java.util.Set
;
import
com.yahoo.ycsb.ByteIterator
;
/**
* @author nygard_89
* @author Basho Technologies, Inc.
*
*/
final
class
RiakUtils
{
private
RiakUtils
()
{
super
();
}
private
static
byte
[]
toBytes
(
final
int
anInteger
)
{
byte
[]
aResult
=
new
byte
[
4
];
aResult
[
0
]
=
(
byte
)
(
anInteger
>>
24
);
aResult
[
1
]
=
(
byte
)
(
anInteger
>>
16
);
aResult
[
2
]
=
(
byte
)
(
anInteger
>>
8
);
aResult
[
3
]
=
(
byte
)
(
anInteger
/* >> 0 */
);
return
aResult
;
}
private
static
void
close
(
final
OutputStream
anOutputStream
)
{
try
{
anOutputStream
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
static
byte
[]
serializeTable
(
Map
<
String
,
ByteIterator
>
aTable
)
{
final
ByteArrayOutputStream
anOutputStream
=
new
ByteArrayOutputStream
();
final
Set
<
Map
.
Entry
<
String
,
ByteIterator
>>
theEntries
=
aTable
.
entrySet
();
try
{
for
(
final
Map
.
Entry
<
String
,
ByteIterator
>
anEntry
:
theEntries
)
{
final
byte
[]
aColumnName
=
anEntry
.
getKey
().
getBytes
();
anOutputStream
.
write
(
toBytes
(
aColumnName
.
length
));
anOutputStream
.
write
(
aColumnName
);
final
byte
[]
aColumnValue
=
anEntry
.
getValue
().
toArray
();
anOutputStream
.
write
(
toBytes
(
aColumnValue
.
length
));
anOutputStream
.
write
(
aColumnValue
);
}
return
anOutputStream
.
toByteArray
();
}
catch
(
IOException
e
)
{
throw
new
IllegalStateException
(
e
);
}
finally
{
close
(
anOutputStream
);
}
}
static
Long
getKeyAsLong
(
String
key
)
{
String
keyString
=
key
.
replace
(
"user"
,
""
).
replaceFirst
(
"^0*"
,
""
);
return
Long
.
parseLong
(
keyString
);
}
}
Event Timeline
Log In to Comment