1 30 31 32 package org.hsqldb; 33 34 import java.io.IOException ; 35 36 import org.hsqldb.lib.InOutUtil; 37 38 46 public class HTTPClientConnection extends HSQLClientConnection { 47 48 static final String ENCODING = "8859_1"; 49 50 public HTTPClientConnection(String host, int port, String path, 51 String database, boolean isTLS, String user, 52 String password) throws HsqlException { 53 super(host, port, path, database, isTLS, user, password); 54 } 55 56 protected void initConnection(String host, int port, 57 boolean isTLS) throws HsqlException {} 58 59 public synchronized Result execute(Result r) throws HsqlException { 60 61 super.openConnection(host, port, isTLS); 62 63 Result result = super.execute(r); 64 65 super.closeConnection(); 66 67 return result; 68 } 69 70 protected void write(Result r) throws IOException , HsqlException { 71 72 rowOut.reset(); 73 r.write(rowOut); 74 dataOutput.write("POST ".getBytes(ENCODING)); 75 dataOutput.write(path.getBytes(ENCODING)); 76 dataOutput.write(" HTTP/1.0\r\n".getBytes(ENCODING)); 77 dataOutput.write( 78 "Content-Type: application/octet-stream\r\n".getBytes(ENCODING)); 79 dataOutput.write(("Content-Length: " + rowOut.size() 80 + "\r\n").getBytes(ENCODING)); 81 dataOutput.write("\r\n".getBytes(ENCODING)); 82 dataOutput.write(rowOut.getOutputStream().getBuffer(), 0, 83 rowOut.getOutputStream().size()); 84 dataOutput.flush(); 85 } 86 87 protected Result read() throws IOException , HsqlException { 88 89 rowOut.reset(); 93 94 for (;;) { 95 int count = InOutUtil.readLine(dataInput, rowOut); 96 97 if (count <= 2) { 98 break; 99 } 100 } 101 102 Result resultIn = Result.read(rowIn, dataInput); 104 105 return resultIn; 106 } 107 } 108 | Popular Tags |