(String[] args)
| 75 | } |
| 76 | |
| 77 | public int run(String[] args) throws Exception { |
| 78 | boolean dumpText = false; |
| 79 | boolean force = false; |
| 80 | String contentType = null; |
| 81 | String url = null; |
| 82 | |
| 83 | String usage = "Usage: ParserChecker [-dumpText] [-forceAs mimeType] url"; |
| 84 | |
| 85 | if (args.length == 0) { |
| 86 | LOG.error(usage); |
| 87 | return (-1); |
| 88 | } |
| 89 | |
| 90 | for (int i = 0; i < args.length; i++) { |
| 91 | if (args[i].equals("-forceAs")) { |
| 92 | force = true; |
| 93 | contentType = args[++i]; |
| 94 | } else if (args[i].equals("-dumpText")) { |
| 95 | dumpText = true; |
| 96 | } else if (i != args.length - 1) { |
| 97 | LOG.error(usage); |
| 98 | System.exit(-1); |
| 99 | } else { |
| 100 | url = URLUtil.toASCII(args[i]); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if (LOG.isInfoEnabled()) { |
| 105 | LOG.info("fetching: " + url); |
| 106 | } |
| 107 | |
| 108 | ProtocolFactory factory = new ProtocolFactory(conf); |
| 109 | Protocol protocol = factory.getProtocol(url); |
| 110 | WebPage page = WebPage.newBuilder().build(); |
| 111 | |
| 112 | ProtocolOutput protocolOutput = protocol.getProtocolOutput(url, page); |
| 113 | |
| 114 | if (!protocolOutput.getStatus().isSuccess()) { |
| 115 | LOG.error("Fetch failed with protocol status: " |
| 116 | + ProtocolStatusUtils.getName(protocolOutput.getStatus().getCode()) |
| 117 | + ": " + ProtocolStatusUtils.getMessage(protocolOutput.getStatus())); |
| 118 | return (-1); |
| 119 | } |
| 120 | Content content = protocolOutput.getContent(); |
| 121 | |
| 122 | if (content == null) { |
| 123 | LOG.error("No content for " + url); |
| 124 | return (-1); |
| 125 | } |
| 126 | page.setBaseUrl(new org.apache.avro.util.Utf8(url)); |
| 127 | page.setContent(ByteBuffer.wrap(content.getContent())); |
| 128 | |
| 129 | if (force) { |
| 130 | content.setContentType(contentType); |
| 131 | } else { |
| 132 | contentType = content.getContentType(); |
| 133 | } |
| 134 |
no test coverage detected