当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils.readStringAndClose方法代码示例

本文整理汇总了Java中org.h2.util.IOUtils.readStringAndClose方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.readStringAndClose方法的具体用法?Java IOUtils.readStringAndClose怎么用?Java IOUtils.readStringAndClose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.util.IOUtils的用法示例。


在下文中一共展示了IOUtils.readStringAndClose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getString

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public String getString() {
    int len = precision > Integer.MAX_VALUE || precision == 0 ?
            Integer.MAX_VALUE : (int) precision;
    try {
        if (type == Value.CLOB) {
            if (small != null) {
                return new String(small, Constants.UTF8);
            }
            return IOUtils.readStringAndClose(getReader(), len);
        }
        byte[] buff;
        if (small != null) {
            buff = small;
        } else {
            buff = IOUtils.readBytesAndClose(getInputStream(), len);
        }
        return StringUtils.convertBytesToHex(buff);
    } catch (IOException e) {
        throw DbException.convertIOException(e, fileName);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:ValueLob.java

示例2: getString

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public String getString() {
    int len = precision > Integer.MAX_VALUE || precision == 0 ?
            Integer.MAX_VALUE : (int) precision;
    try {
        if (type == Value.CLOB) {
            if (small != null) {
                return new String(small, Constants.UTF8);
            }
            return IOUtils.readStringAndClose(getReader(), len);
        }
        byte[] buff;
        if (small != null) {
            buff = small;
        } else {
            buff = IOUtils.readBytesAndClose(getInputStream(), len);
        }
        return StringUtils.convertBytesToHex(buff);
    } catch (IOException e) {
        throw DbException.convertIOException(e, toString());
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:23,代码来源:ValueLobDb.java

示例3: processFile

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private static void processFile(String fileName) throws Exception {
    int idx = fileName.lastIndexOf('.');
    if (idx < 0) {
        return;
    }
    String suffix = fileName.substring(idx + 1);
    if (!suffix.equals("html") && !suffix.equals("xml") && !suffix.equals("jsp")) {
        return;
    }
    // System.out.println("Checking file:" + fileName);
    FileReader reader = new FileReader(fileName);
    String s = IOUtils.readStringAndClose(reader, -1);
    Exception last = null;
    try {
        checkXML(s, !suffix.equals("xml"));
    } catch (Exception e) {
        last = e;
        System.out.println("ERROR in file " + fileName + " " + e.toString());
    }
    if (last != null) {
        last.printStackTrace();
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:24,代码来源:XMLChecker.java

示例4: testLogLimitFalsePositive

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void testLogLimitFalsePositive() throws Exception {
    deleteDb("pageStoreLogLimitFalsePositive");
    String url = "pageStoreLogLimitFalsePositive;TRACE_LEVEL_FILE=2";
    Connection conn = getConnection(url);
    Statement stat = conn.createStatement();
    stat.execute("set max_log_size 1");
    stat.execute("create table test(x varchar)");
    for (int i = 0; i < 1000; ++i) {
        stat.execute("insert into test values (space(2000))");
    }
    stat.execute("checkpoint");
    InputStream in = FileUtils.newInputStream(getBaseDir() +
            "/pageStoreLogLimitFalsePositive.trace.db");
    String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
    assertFalse(s.indexOf("Transaction log could not be truncated") > 0);
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:TestPageStore.java

示例5: get

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Open an URL and get the HTML data.
 *
 * @param url the HTTP URL
 * @return the HTML as a string
 */
String get(String url) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setRequestMethod("GET");
    conn.setInstanceFollowRedirects(true);
    if (acceptLanguage != null) {
        conn.setRequestProperty("accept-language", acceptLanguage);
    }
    conn.connect();
    int code = conn.getResponseCode();
    contentType = conn.getContentType();
    if (code != HttpURLConnection.HTTP_OK) {
        throw new IOException("Result code: " + code);
    }
    InputStream in = conn.getInputStream();
    String result = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
    conn.disconnect();
    return result;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:25,代码来源:WebClient.java

示例6: testWriteColumnHeader

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void testWriteColumnHeader() throws Exception {
    Connection conn = getConnection("csv");
    Statement stat = conn.createStatement();
    stat.execute("call csvwrite('" + getBaseDir() +
            "/test.tsv', 'select x from dual', 'writeColumnHeader=false')");
    String x = IOUtils.readStringAndClose(IOUtils.getReader(
            FileUtils.newInputStream(getBaseDir() + "/test.tsv")), -1);
    assertEquals("\"1\"", x.trim());
    stat.execute("call csvwrite('" + getBaseDir() +
            "/test.tsv', 'select x from dual', 'writeColumnHeader=true')");
    x = IOUtils.readStringAndClose(IOUtils.getReader(
            FileUtils.newInputStream(getBaseDir() + "/test.tsv")), -1);
    x = x.trim();
    assertTrue(x.startsWith("\"X\""));
    assertTrue(x.endsWith("\"1\""));
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:18,代码来源:TestCsv.java

示例7: createClob

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Create a CLOB value from a stream.
 *
 * @param in the reader
 * @param length the number of characters to read, or -1 for no limit
 * @param handler the data handler
 * @return the lob value
 */
private static ValueLob createClob(Reader in, long length,
        DataHandler handler) {
    try {
        if (handler == null) {
            String s = IOUtils.readStringAndClose(in, (int) length);
            return createSmallLob(Value.CLOB, s.getBytes(Constants.UTF8));
        }
        boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
        long remaining = Long.MAX_VALUE;
        if (length >= 0 && length < remaining) {
            remaining = length;
        }
        int len = getBufferSize(handler, compress, remaining);
        char[] buff;
        if (len >= Integer.MAX_VALUE) {
            String data = IOUtils.readStringAndClose(in, -1);
            buff = data.toCharArray();
            len = buff.length;
        } else {
            buff = new char[len];
            len = IOUtils.readFully(in, buff, len);
        }
        if (len <= handler.getMaxLengthInplaceLob()) {
            byte[] small = new String(buff, 0, len).getBytes(Constants.UTF8);
            return ValueLob.createSmallLob(Value.CLOB, small);
        }
        ValueLob lob = new ValueLob(Value.CLOB, null);
        lob.createFromReader(buff, len, in, remaining, handler);
        return lob;
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:ValueLob.java

示例8: createTempClob

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Create a temporary CLOB value from a stream.
 *
 * @param in the reader
 * @param length the number of characters to read, or -1 for no limit
 * @param handler the data handler
 * @return the lob value
 */
public static ValueLobDb createTempClob(Reader in, long length,
        DataHandler handler) {
    BufferedReader reader;
    if (in instanceof BufferedReader) {
        reader = (BufferedReader) in;
    } else {
        reader = new BufferedReader(in, Constants.IO_BUFFER_SIZE);
    }
    try {
        boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
        long remaining = Long.MAX_VALUE;
        if (length >= 0 && length < remaining) {
            remaining = length;
        }
        int len = getBufferSize(handler, compress, remaining);
        char[] buff;
        if (len >= Integer.MAX_VALUE) {
            String data = IOUtils.readStringAndClose(reader, -1);
            buff = data.toCharArray();
            len = buff.length;
        } else {
            buff = new char[len];
            reader.mark(len);
            len = IOUtils.readFully(reader, buff, len);
        }
        if (len <= handler.getMaxLengthInplaceLob()) {
            byte[] small = new String(buff, 0, len).getBytes(Constants.UTF8);
            return ValueLobDb.createSmallLob(Value.CLOB, small, len);
        }
        reader.reset();
        ValueLobDb lob = new ValueLobDb(handler, reader, remaining);
        return lob;
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:45,代码来源:ValueLobDb.java

示例9: testLogLimit

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void testLogLimit() throws Exception {
    if (config.mvStore) {
        return;
    }
    deleteDb("pageStoreLogLimit");
    Connection conn, conn2;
    Statement stat, stat2;
    String url = "pageStoreLogLimit;TRACE_LEVEL_FILE=2";
    conn = getConnection(url);
    stat = conn.createStatement();
    stat.execute("create table test(id int primary key)");
    conn.setAutoCommit(false);
    stat.execute("insert into test values(1)");

    conn2 = getConnection(url);
    stat2 = conn2.createStatement();
    stat2.execute("create table t2(id identity, name varchar)");
    stat2.execute("set max_log_size 1");
    for (int i = 0; i < 10; i++) {
        stat2.execute("insert into t2(name) " +
                "select space(100) from system_range(1, 1000)");
    }
    InputStream in = FileUtils.newInputStream(getBaseDir() +
            "/pageStoreLogLimit.trace.db");
    String s = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
    assertTrue(s.indexOf("Transaction log could not be truncated") > 0);
    conn.commit();
    ResultSet rs = stat2.executeQuery("select * from test");
    assertTrue(rs.next());
    conn2.close();
    conn.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:33,代码来源:TestPageStore.java

示例10: testCorrupt

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void testCorrupt() throws Exception {
    if (config.mvStore) {
        // not needed for MV_STORE=TRUE
        return;
    }
    DeleteDbFiles.execute(getBaseDir(), "recovery", true);
    Connection conn = getConnection("recovery");
    Statement stat = conn.createStatement();
    stat.execute("create table test(id int, name varchar) as " +
            "select 1, 'Hello World1'");
    conn.close();
    FileChannel f = FileUtils.open(getBaseDir() + "/recovery.h2.db", "rw");
    byte[] buff = new byte[Constants.DEFAULT_PAGE_SIZE];
    while (f.position() < f.size()) {
        FileUtils.readFully(f, ByteBuffer.wrap(buff));
        if (new String(buff).contains("Hello World1")) {
            buff[buff.length - 1]++;
            f.position(f.position() - buff.length);
            f.write(ByteBuffer.wrap(buff));
        }
    }
    f.close();
    Recover.main("-dir", getBaseDir(), "-db", "recovery");
    String script = IOUtils.readStringAndClose(
            new InputStreamReader(
            FileUtils.newInputStream(getBaseDir() + "/recovery.h2.sql")), -1);
    assertContains(script, "checksum mismatch");
    assertContains(script, "dump:");
    assertContains(script, "Hello World2");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:31,代码来源:TestRecovery.java

示例11: test

import org.h2.util.IOUtils; //导入方法依赖的package包/类
@Override
public void test() throws Exception {
    String s = "\u00ef\u00f6\u00fc";
    StringReader r = new StringReader(s);
    InputStream in = new ReaderInputStream(r);
    byte[] buff = IOUtils.readBytesAndClose(in, 0);
    InputStream in2 = new ByteArrayInputStream(buff);
    Reader r2 = IOUtils.getBufferedReader(in2);
    String s2 = IOUtils.readStringAndClose(r2, Integer.MAX_VALUE);
    assertEquals(s, s2);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:12,代码来源:TestReader.java

示例12: upload

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * Upload a file.
 *
 * @param url the target URL
 * @param fileName the file name to post
 * @param in the input stream
 * @return the result
 */
String upload(String url, String fileName, InputStream in) throws IOException {
    HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setUseCaches(false);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Connection", "Keep-Alive");
    String boundary = UUID.randomUUID().toString();
    conn.setRequestProperty("Content-Type",
            "multipart/form-data;boundary="+boundary);
    conn.connect();
    DataOutputStream out = new DataOutputStream(conn.getOutputStream());
    out.writeBytes("--" + boundary + "--\r\n");
    out.writeBytes("Content-Disposition: form-data; name=\"upload\";"
            + " filename=\"" + fileName +"\"\r\n\r\n");
    IOUtils.copyAndCloseInput(in, out);
    out.writeBytes("\r\n--" + boundary + "--\r\n");
    out.close();
    int code = conn.getResponseCode();
    if (code != HttpURLConnection.HTTP_OK) {
        throw new IOException("Result code: " + code);
    }
    in = conn.getInputStream();
    String result = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
    conn.disconnect();
    return result;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:36,代码来源:WebClient.java

示例13: testFileRead

import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void testFileRead() throws Exception {
    Connection conn = getConnection("functions");
    Statement stat = conn.createStatement();
    String fileName = getBaseDir() + "/test.txt";
    Properties prop = System.getProperties();
    OutputStream out = FileUtils.newOutputStream(fileName, false);
    prop.store(out, "");
    out.close();
    ResultSet rs = stat.executeQuery("SELECT LENGTH(FILE_READ('" +
            fileName + "')) LEN");
    rs.next();
    assertEquals(FileUtils.size(fileName), rs.getInt(1));
    rs = stat.executeQuery("SELECT FILE_READ('" +
            fileName + "') PROP");
    rs.next();
    Properties p2 = new Properties();
    p2.load(rs.getBinaryStream(1));
    assertEquals(prop.size(), p2.size());
    rs = stat.executeQuery("SELECT FILE_READ('" +
            fileName + "', NULL) PROP");
    rs.next();
    String ps = rs.getString(1);
    InputStreamReader r = new InputStreamReader(FileUtils.newInputStream(fileName));
    String ps2 = IOUtils.readStringAndClose(r, -1);
    assertEquals(ps, ps2);
    conn.close();
    FileUtils.delete(fileName);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:29,代码来源:TestFunctions.java

示例14: asString

import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
 * INTERNAL.
 * Convert the object to a string.
 *
 * @param data the object
 * @param type the SQL type
 * @return the string
 */
protected static String asString(Object data, int type) throws SQLException {
    if (data == null) {
        return "NULL";
    }
    switch (type) {
    case Types.BIT:
    case Types.BOOLEAN:
    case Types.INTEGER:
    case Types.BIGINT:
    case Types.DECIMAL:
    case Types.DOUBLE:
    case Types.FLOAT:
    case Types.NUMERIC:
    case Types.REAL:
    case Types.SMALLINT:
    case Types.TINYINT:
    case Types.DATE:
    case Types.TIME:
    case Types.TIMESTAMP:
    case Types.LONGVARCHAR:
    case Types.CHAR:
    case Types.VARCHAR:
        return data.toString();
    case Types.CLOB:
        try {
            if (data instanceof Clob) {
                data = ((Clob) data).getCharacterStream();
            }
            return IOUtils.readStringAndClose((Reader) data, -1);
        } catch (IOException e) {
            throw DbException.toSQLException(e);
        }
    case Types.VARBINARY:
    case Types.LONGVARBINARY:
    case Types.BINARY:
    case Types.JAVA_OBJECT:
    case Types.OTHER:
    case Types.BLOB:
    case Types.STRUCT:
    case Types.REF:
    case Types.NULL:
    case Types.ARRAY:
    case Types.DATALINK:
    case Types.DISTINCT:
        throw throwException("Unsupported column data type: " + type);
    default:
        return "";
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:58,代码来源:FullText.java

示例15: convert

import org.h2.util.IOUtils; //导入方法依赖的package包/类
public static Object convert(Object o, Class<?> targetType) {
    if (o == null) {
        return null;
    }
    Class<?> currentType = o.getClass();
    if (targetType.isAssignableFrom(currentType)) {
        return o;
    }
    if (targetType == String.class) {
        if (Clob.class.isAssignableFrom(currentType)) {
            Clob c = (Clob) o;
            try {
                Reader r = c.getCharacterStream();
                return IOUtils.readStringAndClose(r, -1);
            } catch (Exception e) {
                throw new RuntimeException(
                        "Error converting CLOB to String: " + e.toString(),
                        e);
            }
        }
        return o.toString();
    }
    if (Number.class.isAssignableFrom(currentType)) {
        Number n = (Number) o;
        if (targetType == Byte.class) {
            return n.byteValue();
        } else if (targetType == Short.class) {
            return n.shortValue();
        } else if (targetType == Integer.class) {
            return n.intValue();
        } else if (targetType == Long.class) {
            return n.longValue();
        } else if (targetType == Double.class) {
            return n.doubleValue();
        } else if (targetType == Float.class) {
            return n.floatValue();
        }
    }
    throw new RuntimeException("Can not convert the value " + o + " from "
            + currentType + " to " + targetType);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:42,代码来源:ClassUtils.java


注:本文中的org.h2.util.IOUtils.readStringAndClose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。