• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-core/src/main/java/com/alicp/jetcache/external/ExternalKeyUtil.java
1
package com.alicp.jetcache.external;
2

3
import com.alicp.jetcache.CacheException;
4

5
import java.io.ByteArrayOutputStream;
6
import java.io.IOException;
7
import java.io.ObjectOutputStream;
8
import java.io.Serializable;
9
import java.nio.charset.StandardCharsets;
10
import java.text.SimpleDateFormat;
11
import java.util.Date;
12

13
/**
14
 * Created on 2016/12/30.
15
 *
16
 * @author huangli
17
 */
18
public class ExternalKeyUtil {
×
19
    public static byte[] buildKeyAfterConvert(Object newKey, String prefix) throws IOException {
20
        if (newKey == null) {
×
21
            throw new NullPointerException("key can't be null");
×
22
        }
23
        byte[] keyBytesWithOutPrefix;
24
        if (newKey instanceof String) {
×
25
            keyBytesWithOutPrefix = newKey.toString().getBytes(StandardCharsets.UTF_8);
×
26
        } else if (newKey instanceof byte[]) {
×
27
            keyBytesWithOutPrefix = (byte[]) newKey;
×
28
        } else if (newKey instanceof Number) {
×
29
            keyBytesWithOutPrefix = (newKey.getClass().getSimpleName() + newKey).getBytes(StandardCharsets.UTF_8);
×
30
        } else if (newKey instanceof Date) {
×
31
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss,SSS");
×
32
            keyBytesWithOutPrefix = (newKey.getClass().getSimpleName() + sdf.format(newKey)).getBytes();
×
33
        } else if (newKey instanceof Boolean) {
×
34
            keyBytesWithOutPrefix = newKey.toString().getBytes(StandardCharsets.UTF_8);
×
35
        } else if (newKey instanceof Serializable) {
×
36
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
×
37
            ObjectOutputStream os = new ObjectOutputStream(bos);
×
38
            os.writeObject(newKey);
×
39
            os.close();
×
40
            bos.close();
×
41
            keyBytesWithOutPrefix = bos.toByteArray();
×
42
        } else {
×
43
            throw new CacheException("can't convert key of class: " + newKey.getClass());
×
44
        }
45
        byte[] prefixBytes = prefix.getBytes(StandardCharsets.UTF_8);
×
46
        byte[] rt = new byte[prefixBytes.length + keyBytesWithOutPrefix.length];
×
47
        System.arraycopy(prefixBytes, 0, rt, 0, prefixBytes.length);
×
48
        System.arraycopy(keyBytesWithOutPrefix, 0, rt, prefixBytes.length, keyBytesWithOutPrefix.length);
×
49
        return rt;
×
50
    }
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc