Apache Nutch is an extensible and scalable web crawler
remove deprecated objects ParseText and ParseStatus
Julien Niocheb6e1c19a3a81
diff --git a/src/java/org/apache/nutch/parse/ParseStatus.java b/src/java/org/apache/nutch/parse/ParseStatus.javadeleted file mode 100644index a3cb9b330..000000000--- a/src/java/org/apache/nutch/parse/ParseStatus.java+++ /dev/null@@ -1,228 +0,0 @@-/*- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You 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.- */-/*- * Created on Apr 28, 2005- * Author: Andrzej Bialecki <[email protected]>- *- */-package org.apache.nutch.parse;--import java.io.DataInput;-import java.io.DataOutput;-import java.io.IOException;--import org.apache.hadoop.io.VersionMismatchException;-import org.apache.hadoop.io.Writable;-import org.apache.hadoop.io.WritableUtils;---/**- * @author Andrzej Bialecki <[email protected]>- */-@Deprecated-public class ParseStatus implements Writable, ParseStatusCodes {-- private final static byte VERSION = 2;-- public static final ParseStatus STATUS_NOTPARSED = new ParseStatus(NOTPARSED);- public static final ParseStatus STATUS_SUCCESS = new ParseStatus(SUCCESS);- public static final ParseStatus STATUS_FAILURE = new ParseStatus(FAILED);-- private byte majorCode = 0;- private short minorCode = 0;- private String[] args = null;-- public byte getVersion() {- return VERSION;- }-- public ParseStatus() {-- }-- public ParseStatus(int majorCode, int minorCode, String[] args) {- this.args = args;- this.majorCode = (byte)majorCode;- this.minorCode = (short)minorCode;- }-- public ParseStatus(int majorCode) {- this(majorCode, 0, (String[])null);- }-- public ParseStatus(int majorCode, String[] args) {- this(majorCode, 0, args);- }-- public ParseStatus(int majorCode, int minorCode) {- this(majorCode, minorCode, (String[])null);- }-- /** Simplified constructor for passing just a text message. */- public ParseStatus(int majorCode, int minorCode, String message) {- this(majorCode, minorCode, new String[]{message});- }-- /** Simplified constructor for passing just a text message. */- public ParseStatus(int majorCode, String message) {- this(majorCode, 0, new String[]{message});- }-- public ParseStatus(Throwable t) {- this(FAILED, FAILED_EXCEPTION, new String[]{t.toString()});- }-- public static ParseStatus read(DataInput in) throws IOException {- ParseStatus res = new ParseStatus();- res.readFields(in);- return res;- }-- public void readFields(DataInput in) throws IOException {- byte version = in.readByte();- switch(version) {- case 1:- majorCode = in.readByte();- minorCode = in.readShort();- args = WritableUtils.readCompressedStringArray(in);- break;- case 2:- majorCode = in.readByte();- minorCode = in.readShort();- args = WritableUtils.readStringArray(in);- break;- default:- throw new VersionMismatchException(VERSION, version);- }- }-- public void write(DataOutput out) throws IOException {- out.writeByte(VERSION);- out.writeByte(majorCode);- out.writeShort(minorCode);- if (args == null) {- out.writeInt(-1);- } else {- WritableUtils.writeStringArray(out, args);- }- }-- /** A convenience method. Returns true if majorCode is SUCCESS, false- * otherwise.- */-- public boolean isSuccess() {- return majorCode == SUCCESS;- }-- /** A convenience method. Return a String representation of the first- * argument, or null.- */- public String getMessage() {- if (args != null && args.length > 0 && args[0] != null)- return args[0];- return null;- }-- public String[] getArgs() {- return args;- }-- public int getMajorCode() {- return majorCode;- }-- public int getMinorCode() {- return minorCode;- }-- /** A convenience method. Creates an empty Parse instance,- * which returns this status.- */- //public Parse getEmptyParse(Configuration conf) {- // return new Parse("", "", new Outlink[0], this);- //}-- /** A convenience method. Creates an empty ParseResult,- * which contains this status.- */- //public ParseResult getEmptyParseResult(String url, Configuration conf) {- // return ParseResult.createParseResult(url, getEmptyParse(conf));- //}-- @Override- public String toString() {- StringBuffer res = new StringBuffer();- String name = null;- if (majorCode >= 0 && majorCode < majorCodes.length) name = majorCodes[majorCode];- else name = "UNKNOWN!";- res.append(name + "(" + majorCode + "," + minorCode + ")");- if (args != null) {- if (args.length == 1) {- res.append(": " + String.valueOf(args[0]));- } else {- for (int i = 0; i < args.length; i++) {- if (args[i] != null)- res.append(", args[" + i + "]=" + String.valueOf(args[i]));- }- }- }- return res.toString();- }-- public void setArgs(String[] args) {- this.args = args;- }-- public void setMessage(String msg) {- if (args == null || args.length == 0) {- args = new String[1];- }- args[0] = msg;- }-- public void setMajorCode(byte majorCode) {- this.majorCode = majorCode;- }-- public void setMinorCode(short minorCode) {- this.minorCode = minorCode;- }-- @Override- public boolean equals(Object o) {- if (o == null) return false;- if (!(o instanceof ParseStatus)) return false;- boolean res = true;- ParseStatus other = (ParseStatus)o;- res = res && (this.majorCode == other.majorCode) &&- (this.minorCode == other.minorCode);- if (!res) return res;- if (this.args == null) {- if (other.args == null) return true;- else return false;- } else {- if (other.args == null) return false;- if (other.args.length != this.args.length) return false;- for (int i = 0; i < this.args.length; i++) {- if (!this.args[i].equals(other.args[i])) return false;- }- }- return true;- }-}-diff --git a/src/java/org/apache/nutch/parse/ParseText.java b/src/java/org/apache/nutch/parse/ParseText.javadeleted file mode 100644index 6189b2a81..000000000--- a/src/java/org/apache/nutch/parse/ParseText.java+++ /dev/null@@ -1,113 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You 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.apache.nutch.parse;--import java.io.*;-import org.apache.hadoop.io.*;-import org.apache.hadoop.util.GenericOptionsParser;-import org.apache.hadoop.fs.*;-import org.apache.hadoop.conf.*;-import org.apache.nutch.util.NutchConfiguration;--/* The text conversion of page's content, stored using gzip compression.- * @see Parse#getText()- */-public final class ParseText implements Writable {- public static final String DIR_NAME = "parse_text";-- private final static byte VERSION = 2;-- public ParseText() {}- private String text;-- public ParseText(String text){- this.text = text;- }-- public void readFields(DataInput in) throws IOException {- byte version = in.readByte();- switch (version) {- case 1:- text = WritableUtils.readCompressedString(in);- break;- case VERSION:- text = Text.readString(in);- break;- default:- throw new VersionMismatchException(VERSION, version);- }- }-- public final void write(DataOutput out) throws IOException {- out.write(VERSION);- Text.writeString(out, text);- }-- public final static ParseText read(DataInput in) throws IOException {- ParseText parseText = new ParseText();- parseText.readFields(in);- return parseText;- }-- //- // Accessor methods- //- public String getText() { return text; }-- public boolean equals(Object o) {- if (!(o instanceof ParseText))- return false;- ParseText other = (ParseText)o;- return this.text.equals(other.text);- }-- public String toString() {- return text;- }-- public static void main(String args[]) throws Exception {- String usage = "ParseText (-local | -dfs <namenode:port>) recno segment";-- if (args.length < 3) {- System.out.println("usage:" + usage);- return;- }-- GenericOptionsParser optParser =- new GenericOptionsParser(NutchConfiguration.create(), args);- String[] argv = optParser.getRemainingArgs();- Configuration conf = optParser.getConfiguration();-- FileSystem fs = FileSystem.get(conf);- try {- int recno = Integer.parseInt(argv[0]);- String segment = argv[1];- String filename = new Path(segment, ParseText.DIR_NAME).toString();-- ParseText parseText = new ParseText();- ArrayFile.Reader parseTexts = new ArrayFile.Reader(fs, filename, conf);-- parseTexts.get(recno, parseText);- System.out.println("Retrieved " + recno + " from file " + filename);- System.out.println(parseText);- parseTexts.close();- } finally {- fs.close();- }- }-}diff --git a/src/test/org/apache/nutch/parse/TestParseText.java b/src/test/org/apache/nutch/parse/TestParseText.javadeleted file mode 100644index 7aa1cd8d9..000000000--- a/src/test/org/apache/nutch/parse/TestParseText.java+++ /dev/null@@ -1,38 +0,0 @@-/**- * Licensed to the Apache Software Foundation (ASF) under one or more- * contributor license agreements. See the NOTICE file distributed with- * this work for additional information regarding copyright ownership.- * The ASF licenses this file to You 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.apache.nutch.parse;--import org.apache.nutch.util.WritableTestUtils;--import junit.framework.TestCase;--/** Unit tests for ParseText. */--public class TestParseText extends TestCase {- public TestParseText(String name) { super(name); }-- public void testParseText() throws Exception {-- String page = "Hello World The Quick Brown Fox Jumped Over the Lazy Fox";-- ParseText s = new ParseText(page);-- WritableTestUtils.testWritable(s);- }--}