protected TextArrayWritable queryHosts(ContentSource cs, String matchHost,
    		String replaceHost)
        throws IOException {
        Session session = null;
        ResultSequence result = null;
        try {
            session = cs.newSession();
            AdhocQuery query = session.newAdhocQuery(HOSTS_QUERY);
            // query hosts
            RequestOptions options = new RequestOptions();
            options.setDefaultXQueryVersion("1.0-ml");
            query.setOptions(options);
            result = session.submitRequest(query);

            ArrayList<Text> hosts = new ArrayList<Text>();
            while (result.hasNext()) {
                ResultItem item = result.next();
                String host = item.asString();
                if (matchHost != null && host.equals(matchHost)) {
                	hosts.add(new Text(replaceHost));
                } else {
                    hosts.add(new Text(host));
                }
            }
            if (hosts.isEmpty()) {
                throw new IOException("Target database has no forests attached: "
                        + "check forests in database");
            }
            return new TextArrayWritable(hosts.toArray(new Text[hosts.size()]));
        } catch (RequestException e) {
            LOG.error(e.getMessage(), e);
            throw new IOException(e);
        } finally {
            if (result != null) {
                result.close();
            }
            if (session != null) {
                session.close();
            }
        }
    }
protected TextArrayWritable queryHosts ( ContentSource cs , String matchHost , String replaceHost ) throws IOException { Session session = null ; ResultSequence result = null ; try { session = cs . newSession ( ) ; AdhocQuery query = session . newAdhocQuery ( HOSTS_QUERY ) ; RequestOptions options = new RequestOptions ( ) ; options . setDefaultXQueryVersion ( "1.0-ml" ) ; query . setOptions ( options ) ; result = session . submitRequest ( query ) ; ArrayList < Text > hosts = new ArrayList < Text > ( ) ; while ( result . hasNext ( ) ) { ResultItem item = result . next ( ) ; String host = item . asString ( ) ; if ( matchHost != null && host . equals ( matchHost ) ) { hosts . add ( new Text ( replaceHost ) ) ; } else { hosts . add ( new Text ( host ) ) ; } } if ( hosts . isEmpty ( ) ) { throw new IOException ( "Target database has no forests attached: " + "check forests in database" ) ; } return new TextArrayWritable ( hosts . toArray ( new Text [ hosts . size ( ) ] ) ) ; } catch ( RequestException e ) { LOG . error ( e . getMessage ( ) , e ) ; throw new IOException ( e ) ; } finally { if ( result != null ) { result . close ( ) ; } if ( session != null ) { session . close ( ) ; } } }
with outputHost