use of php.runtime.ext.core.classes.stream.MiscStream in project jphp by jphp-compiler.
the class PHttpClient method applyConnection.
@Signature
protected void applyConnection(PHttpResponse response, URLConnection _connection, Environment env) throws IOException {
if (_connection instanceof HttpURLConnection) {
HttpURLConnection connection = (HttpURLConnection) _connection;
response.setStatusCode(connection.getResponseCode());
response.setStatusMessage(connection.getResponseMessage());
try {
response.setBodyStream(new MiscStream(env, connection.getInputStream()));
} catch (IOException e) {
response.setBodyStream(new MiscStream(env, connection.getErrorStream()));
}
// headers.
ArrayMemory headers = new ArrayMemory();
Map<String, List<String>> headerFields = connection.getHeaderFields();
for (Map.Entry<String, List<String>> entry : headerFields.entrySet()) {
String name = entry.getKey();
List<String> value = entry.getValue();
if (value.size() == 1) {
headers.putAsKeyString(name, StringMemory.valueOf(value.get(0)));
} else {
headers.putAsKeyString(name, ArrayMemory.ofStringCollection(value));
}
}
response.setHeaders(headers);
ArrayMemory cookies = new ArrayMemory();
String cookieHeader = connection.getHeaderField("Set-Cookie");
if (cookieHeader != null && !cookieHeader.isEmpty()) {
List<HttpCookie> httpCookies = HttpCookie.parse(cookieHeader);
for (HttpCookie cookie : httpCookies) {
ArrayMemory memory = HttpClientExtension.cookieToArray(cookie);
cookies.putAsKeyString(cookie.getName(), memory);
}
}
response.setRawCookies(cookies);
} else {
throw new IllegalStateException("Argument 2 must be instance of HttpURLConnection");
}
}
use of php.runtime.ext.core.classes.stream.MiscStream in project jphp by jphp-compiler.
the class PSqlResult method getTyped.
public Memory getTyped(Environment env, int index) throws SQLException {
index += 1;
ResultSet set = resultSet;
int type = metaData.getColumnType(index);
if (set.getObject(index) == null) {
return Memory.NULL;
}
switch(type) {
case Types.INTEGER:
case Types.SMALLINT:
case Types.TINYINT:
case Types.BIT:
return LongMemory.valueOf(set.getLong(index));
case Types.BOOLEAN:
return TrueMemory.valueOf(set.getBoolean(index));
case Types.FLOAT:
case Types.DOUBLE:
case Types.DECIMAL:
return DoubleMemory.valueOf(set.getDouble(index));
case Types.NULL:
return Memory.NULL;
case Types.TIME:
Time time = set.getTime(index);
return ObjectMemory.valueOf(new WrapTime(env, time));
case Types.TIMESTAMP:
Timestamp timestamp = set.getTimestamp(index);
return ObjectMemory.valueOf(new WrapTime(env, timestamp));
case Types.DATE:
Date date = set.getDate(index);
return ObjectMemory.valueOf(new WrapTime(env, date));
case Types.VARCHAR:
case Types.LONGVARCHAR:
case Types.CHAR:
case Types.BIGINT:
return StringMemory.valueOf(set.getString(index));
case Types.NVARCHAR:
case Types.LONGNVARCHAR:
return StringMemory.valueOf(set.getNString(index));
case Types.BINARY:
return new BinaryMemory(set.getBytes(index));
case Types.BLOB:
case Types.CLOB:
case Types.NCLOB:
try {
Blob blob = set.getBlob(index);
return ObjectMemory.valueOf(new MiscStream(env, blob.getBinaryStream()));
} catch (SQLException e) {
return new BinaryMemory(set.getBytes(index));
}
default:
return StringMemory.valueOf(set.getString(index));
}
}
Aggregations