Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
<version>17.0</version>
</dependency>

<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
</dependency>
<dependency>
<groupId>org.htmlparser</groupId>
<artifactId>htmlparser</artifactId>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/archive/extract/RealCDXExtractorOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -337,7 +338,14 @@ private String scanHeadersLC(JSONObject o, String match, String defaultVal) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
for(String key : JSONObject.getNames(o)) {
Iterator<String> namesIterator = o.keys();
String[] names = new String[o.length()];
int i = 0;
while(namesIterator.hasNext()) {
names[i] = namesIterator.next();
i++;
}
for(String key : names) {
if(lc.equals(key.toLowerCase().trim())) {
try {
return o.getString(key).trim();
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/org/archive/extract/WATExtractorOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,8 @@ private void writeWARCMDRecord(OutputStream recOut, MetaData md,
ByteArrayOutputStream bos = new ByteArrayOutputStream();

OutputStreamWriter osw = new OutputStreamWriter(bos, UTF8);
try {
md.write(osw);
} catch (JSONException e1) {
e1.printStackTrace();
throw new IOException(e1);
}
String contents = md.toString();
osw.write(contents, 0, contents.length());
osw.flush();
// ByteArrayInputStream bais = new ByteArrayInputStream(md.toString().getBytes("UTF-8"));
Date capDate;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/archive/format/arc/FiledescRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void addMetaData(String name, String value) {
JSONObject jo = new JSONObject();
jo.put("name", name);
jo.put("value", value);
metadata.append("MetaData",jo);
metadata.accumulate("MetaData",jo);
} catch(JSONException e) {
LOG.warning(e.getMessage());
}
Expand Down Expand Up @@ -87,4 +87,4 @@ public String getFormat() {
public void setFormat(String format) {
this.format = format;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.InputStreamReader;
import java.nio.charset.Charset;

import com.google.common.io.CharStreams;
import org.archive.resource.MetaData;
import org.archive.resource.Resource;
import org.archive.resource.ResourceConstants;
Expand All @@ -27,7 +28,8 @@ public Resource getResource(InputStream is, MetaData parentMetaData,

MetaData md;
try {
md = new MetaData(new JSONTokener(new InputStreamReader(is, UTF8)));
String input = CharStreams.toString(new InputStreamReader(is, UTF8));
md = new MetaData(new JSONTokener(input));
} catch (JSONException e) {
throw new ResourceParseException(e);
}
Expand Down
116 changes: 116 additions & 0 deletions src/main/java/org/json/JSON.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* 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 org.json;

class JSON {
/**
* Returns the input if it is a JSON-permissible value; throws otherwise.
*/
static double checkDouble(double d) throws JSONException {
if (Double.isInfinite(d) || Double.isNaN(d)) {
throw new JSONException("Forbidden numeric value: " + d);
}
return d;
}

static Boolean toBoolean(Object value) {
if (value instanceof Boolean) {
return (Boolean) value;
} else if (value instanceof String) {
String stringValue = (String) value;
if ("true".equalsIgnoreCase(stringValue)) {
return true;
} else if ("false".equalsIgnoreCase(stringValue)) {
return false;
}
}
return null;
}

static Double toDouble(Object value) {
if (value instanceof Double) {
return (Double) value;
} else if (value instanceof Number) {
return ((Number) value).doubleValue();
} else if (value instanceof String) {
try {
return Double.valueOf((String) value);
} catch (NumberFormatException ignored) {
}
}
return null;
}

static Integer toInteger(Object value) {
if (value instanceof Integer) {
return (Integer) value;
} else if (value instanceof Number) {
return ((Number) value).intValue();
} else if (value instanceof String) {
try {
return (int) Double.parseDouble((String) value);
} catch (NumberFormatException ignored) {
}
}
return null;
}

static Long toLong(Object value) {
if (value instanceof Long) {
return (Long) value;
} else if (value instanceof Number) {
return ((Number) value).longValue();
} else if (value instanceof String) {
try {
return (long) Double.parseDouble((String) value);
} catch (NumberFormatException ignored) {
}
}
return null;
}

static String toString(Object value) {
if (value instanceof String) {
return (String) value;
} else if (value != null) {
return String.valueOf(value);
}
return null;
}

public static JSONException typeMismatch(Object indexOrName, Object actual,
String requiredType) throws JSONException {
if (actual == null) {
throw new JSONException("Value at " + indexOrName + " is null.");
} else {
throw new JSONException("Value " + actual + " at " + indexOrName
+ " of type " + actual.getClass().getName()
+ " cannot be converted to " + requiredType);
}
}

public static JSONException typeMismatch(Object actual, String requiredType)
throws JSONException {
if (actual == null) {
throw new JSONException("Value is null.");
} else {
throw new JSONException("Value " + actual
+ " of type " + actual.getClass().getName()
+ " cannot be converted to " + requiredType);
}
}
}
Loading