Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
XRYKeyValuePair.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datasourceprocessors.xry;
20 
30 class XRYKeyValuePair {
31 
32  private static final char KEY_VALUE_DELIMITER = ':';
33 
34  private final String key;
35  private final String value;
36  private final String namespace;
37 
38  XRYKeyValuePair(String key, String value, String namespace) {
39  this.key = key.trim();
40  this.value = value.trim();
41  this.namespace = namespace.trim();
42  }
43 
52  boolean hasKey(String targetKey) {
53  String normalizedKey = key.toLowerCase();
54  String normalizedTargetKey = targetKey.trim().toLowerCase();
55  return normalizedKey.equals(normalizedTargetKey);
56  }
57 
61  String getValue() {
62  return value;
63  }
64 
68  String getKey() {
69  return key;
70  }
71 
75  String getNamespace() {
76  return namespace;
77  }
78 
84  static boolean isPair(String input) {
85  int dataKeyIndex = input.indexOf(KEY_VALUE_DELIMITER);
86  //No key structure found.
87  return dataKeyIndex != -1;
88  }
89 
100  static XRYKeyValuePair from(String input, String namespace) {
101  if(!isPair(input)) {
102  throw new IllegalArgumentException("Input does not have the structure"
103  + " of a key value pair");
104  }
105 
106  int keyIndex = input.indexOf(KEY_VALUE_DELIMITER);
107  String parsedKey = input.substring(0, keyIndex);
108  String parsedValue = input.substring(keyIndex + 1);
109  return new XRYKeyValuePair(parsedKey, parsedValue, namespace);
110  }
111 
121  static XRYKeyValuePair from(String input) {
122  return from(input, "");
123  }
124 
125  @Override
126  public String toString() {
127  if(namespace.isEmpty()) {
128  return key + " : " + value;
129  }
130  return "(Namespace: " + namespace +") " + key + " : " + value;
131  }
132 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.