httpclient.java

来自「数字图书馆的互操作接口」· Java 代码 · 共 58 行

JAVA
58
字号
package dli2fe.http;

/**
 * Title:        Digial Library Interoperable Interface Fudan Edition
 * Description:  This project contains all the classes required for DLI2FE interface. Developers use these classes to implement the wrapper and client side codes. The basic functions of DLI2FE is as follows:
 * Search: Search a digital library source site.
 * Metadata: Fetch metadata for a site.
 * ResultAccess: Get results for a given query.
 * DLI2FE uses Dublin Core as the basic attribute model, DAV/DASL as the general XML-based query language and CORBA as distributed object transportation mechanism.
 * Copyright:    Copyright (c) 2001
 * Company:      Fudan University
 * @author Carl Tao
 * @version 1.0
 */


import java.io.*;
import java.net.*;
import java.util.*;

public class HTTPClient {

  public final static int DEFAULT_PORT = 80;

  URL url;
  OutputStream out;
  InputStream in;

  public HTTPClient(String url) throws MalformedURLException {

    this(new URL(url));
  }

  public HTTPClient(URL url) {

    this.url = url;
  }

  synchronized void checkOpen() throws IOException {
    if(out == null) {

      Socket socket = new Socket( url.getHost(), url.getPort() > 0 ? url.getPort() : DEFAULT_PORT );
      out = socket.getOutputStream();
      in = socket.getInputStream();
    }
  }

  public OutputStream getOutputStream() throws IOException {
    checkOpen();
    return out;
  }

  public InputStream getInputStream() throws IOException {
    checkOpen();
    return in;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?