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


Java InputStreamReader.read方法代码示例

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


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

示例1: getStringFromInputStream

import java.io.InputStreamReader; //导入方法依赖的package包/类
/**
 * Convert an InputStream in a String
 *
 * @param inputStream InputStream to convert
 *
 * @return String with the content of InputStream
 *
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
public static String getStringFromInputStream(InputStream inputStream) throws UnsupportedEncodingException, IOException {
  
 InputStreamReader inputTxtStream = new InputStreamReader(inputStream, "ISO-8859-1");

  String StrTemp = "";

  if (inputTxtStream != null) {
    final int DATA_BLOCK_SIZE = 2048;

    // Create the byte array to hold the data
    char[] bytes = new char[DATA_BLOCK_SIZE];

    // Read in the bytes
    int numRead = 0;

    while ((numRead = inputTxtStream.read(bytes, 0, bytes.length)) >= 0) {
      StrTemp += new String(bytes, 0, numRead);
    }
  }

  return StrTemp;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:33,代码来源:StreamUtil.java

示例2: getStringFromFile

import java.io.InputStreamReader; //导入方法依赖的package包/类
/**
   * Convert a file to a String using specified encoding ("UTF-8", "UTF-16", "latin1", ...)
   * 
   * @param String filePath, String charset
   * 
   * @return String
   * 
   * @throws UnsupportedEncodingException, IOException
   */
public static String getStringFromFile(String filePath, String charset) throws Exception {

	File file = new File(filePath);
	String str = null;
	int numRead = 0;
	final int DATA_BLOCK_SIZE = 2048;
	
	InputStreamReader isr = new InputStreamReader(new FileInputStream(file), charset);

    if (isr != null) {

      // Create the byte array to hold the data
      char[] charArray = new char[DATA_BLOCK_SIZE];

      while ((numRead = isr.read(charArray, 0, DATA_BLOCK_SIZE)) >= 0) {
        str += new String(charArray, 0, numRead);
      }
      isr.close();
    }

    return str;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:32,代码来源:StreamUtil.java

示例3: BacktrackInputReader

import java.io.InputStreamReader; //导入方法依赖的package包/类
/**
 * Create an object to read the file name passed with the given charset.
 *
 * @param file	The filename to open
 */

public BacktrackInputReader(File file, String charset)
{
	try
	{
		InputStreamReader isr = readerFactory(file, charset);
		data = new char[readerLength(file, isr)];
		max = isr.read(data);
		pos = 0;
		isr.close();
	}
	catch (IOException e)
	{
		throw new InternalException(0, e.getMessage());
	}
}
 
开发者ID:nickbattle,项目名称:FJ-VDMJ,代码行数:22,代码来源:BacktrackInputReader.java

示例4: checkRoot

import java.io.InputStreamReader; //导入方法依赖的package包/类
private static void checkRoot() {
    sRoot = false;
    char[] buff = new char[1024];
    try {
        Process process = Runtime.getRuntime().exec("su");
        OutputStreamWriter output = new OutputStreamWriter(process.getOutputStream());
        InputStreamReader input = new InputStreamReader(process.getInputStream());
        String testStr = "ROOT_TEST";
        output.write("echo " + testStr + "\n");
        output.flush();
        output.write("exit\n");
        output.flush();
        process.waitFor();
        int count = input.read(buff);
        if (count > 0) {
            if (new String(buff, 0, count).startsWith(testStr))
                sRoot = true;
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:23,代码来源:ShellUtils.java

示例5: create

import java.io.InputStreamReader; //导入方法依赖的package包/类
public static Template create(InputStream in) {
	InputStreamReader reader = new InputStreamReader(in);
	char[] buf = new char[4096];
	StringBuilder dest = new StringBuilder();
	while (true) {
		try {
			int nbytes = reader.read(buf);
			if (nbytes < 0)
				break;
			dest.append(buf, 0, nbytes);
		} catch (IOException e) {
			break;
		}
	}
	return new Template(dest.toString());
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:17,代码来源:Template.java

示例6: readFully

import java.io.InputStreamReader; //导入方法依赖的package包/类
public static String readFully(InputStreamReader in) {
	if (in == null) {
		return null;
	}
	try {
		StringWriter result = new StringWriter();
		char[] cbuf = new char[4096];
		int cnt;
		while ((cnt=in.read(cbuf)) > 0) {
			result.write(cbuf, 0, cnt);
		}
		return result.toString();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	finally {
		try {
			in.close();
		} catch (IOException ignore) {}
	}
}
 
开发者ID:ferenc-hechler,项目名称:RollenspielAlexaSkill,代码行数:22,代码来源:TextUtil.java

示例7: run

import java.io.InputStreamReader; //导入方法依赖的package包/类
public void run() {
       /* interrompe il controllato se l'utente preme INVIO */
       logger.info("KeyboardKiller: Press ENTER to cancel task(s).");
	/* aspetta che l'utente prima INVIO */ 
	InputStreamReader inputStreamReader = new InputStreamReader(System.in);
	char answer = '\0'; 
	while (answer=='\0') {
           try {
               answer = (char) inputStreamReader.read();
           } catch (IOException e) {
               logger.info(this.toString() + ": I/O exception: " + e.toString());
           }
	}
	/* ok, ora interrompe i controllati */
	this.cancel(); 
}
 
开发者ID:aswroma3,项目名称:asw,代码行数:17,代码来源:KeyboardKiller.java

示例8: inputStreamToString

import java.io.InputStreamReader; //导入方法依赖的package包/类
/**
 * Using a Reader and a Writer, returns a String from an InputStream.
 */
public static String inputStreamToString(InputStream x,
        int length) throws IOException {

    InputStreamReader in        = new InputStreamReader(x);
    StringWriter      writer    = new StringWriter();
    int               blocksize = 8 * 1024;
    char[]            buffer    = new char[blocksize];

    for (int left = length; left > 0; ) {
        int read = in.read(buffer, 0, left > blocksize ? blocksize
                                                       : left);

        if (read == -1) {
            break;
        }

        writer.write(buffer, 0, read);

        left -= read;
    }

    writer.close();

    return writer.toString();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:29,代码来源:StringConverter.java

示例9: main

import java.io.InputStreamReader; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    InputStreamReader is = new InputStreamReader( System.in );
    Button btn = new Button();
    while (true) {
        System.out.print("Press 'Enter'");
        is.read();
        btn.push();
    }
}
 
开发者ID:bmariesan,项目名称:iStudent,代码行数:10,代码来源:StateDemo.java

示例10: readStream

import java.io.InputStreamReader; //导入方法依赖的package包/类
/**
 * High performance read from an {@link InputStream} into a String
 * 
 * @param inputStream
 *            the input stream from which to read
 * @return the string read from the reader
 * @throws IOException
 *             if an IOException occurs
 */
private static String readStream(InputStream inputStream) throws IOException {
	InputStreamReader reader = new InputStreamReader(inputStream);
	StringWriter sw = new StringWriter();
	char[] buffer = new char[BUFFER_SIZE];
	int pos = 0;
	while ((pos = reader.read(buffer)) != -1) {
		sw.write(buffer, 0, pos);
	}
	return sw.toString();
}
 
开发者ID:kmecpp,项目名称:JSpark,代码行数:20,代码来源:FileUtil.java

示例11: CRCCheck

import java.io.InputStreamReader; //导入方法依赖的package包/类
/**
 * Check if the CRC of the snapshot file matches the digest.
 * @param f The snapshot file object
 * @return The table list as a string
 * @throws IOException If CRC does not match
 */
public static String CRCCheck(File f) throws IOException {
    final FileInputStream fis = new FileInputStream(f);
    try {
        final BufferedInputStream bis = new BufferedInputStream(fis);
        ByteBuffer crcBuffer = ByteBuffer.allocate(4);
        if (4 != bis.read(crcBuffer.array())) {
            throw new EOFException("EOF while attempting to read CRC from snapshot digest");
        }
        final int crc = crcBuffer.getInt();
        final InputStreamReader isr = new InputStreamReader(bis, "UTF-8");
        CharArrayWriter caw = new CharArrayWriter();
        while (true) {
            int nextChar = isr.read();
            if (nextChar == -1) {
                throw new EOFException("EOF while reading snapshot digest");
            }
            if (nextChar == '\n') {
                break;
            }
            caw.write(nextChar);
        }
        String tableList = caw.toString();
        byte tableListBytes[] = tableList.getBytes("UTF-8");
        CRC32 tableListCRC = new CRC32();
        tableListCRC.update(tableListBytes);
        tableListCRC.update("\n".getBytes("UTF-8"));
        final int calculatedValue = (int)tableListCRC.getValue();
        if (crc != calculatedValue) {
            throw new IOException("CRC of snapshot digest did not match digest contents");
        }

        return tableList;
    } finally {
        try {
            if (fis != null)
                fis.close();
        } catch (IOException e) {}
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:46,代码来源:SnapshotUtil.java

示例12: parse

import java.io.InputStreamReader; //导入方法依赖的package包/类
protected void parse(String pPath) {
    try {
        char[] tBytes = new char[1024];
        StringBuilder tBuffer = new StringBuilder();
        InputStream tStream = getClass().getResourceAsStream(pPath);
        if (tStream == null) {
            tStream = ClassLoader.getSystemResourceAsStream(pPath);
        }
        if (tStream == null) {
            tStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(pPath);
        }
        InputStreamReader tReader = new InputStreamReader(tStream, "UTF-8");
        int tCount = tReader.read(tBytes);
        while (tCount > 0) {
            tBuffer.append(new String(tBytes, 0, tCount));
            tCount = tReader.read(tBytes);
        }

        String[] tArr = tBuffer.toString().split("\n");

        createLanguages(tArr[0]);
        for (int i = 1; i < tArr.length; i++) {
            if (tArr[i].indexOf(DELIMITER) > 0) {
                createWord(tArr[i].split(DELIMITER));
            }
        }
        tStream.close();
    }
    catch (Exception e) {
        throw new RuntimeException("Failed to parse dictionary: " + pPath, e);
    }
}
 
开发者ID:cinnober,项目名称:ciguan,代码行数:33,代码来源:AsDictionaryHandler.java

示例13: getStringFromInputStream

import java.io.InputStreamReader; //导入方法依赖的package包/类
private static String getStringFromInputStream(InputStream stream) throws IOException {
    int n = 0;
    char[] buffer = new char[1024 * 4];
    InputStreamReader reader = new InputStreamReader(stream, "UTF8");
    StringWriter writer = new StringWriter();
    while (-1 != (n = reader.read(buffer))) writer.write(buffer, 0, n);
    return writer.toString();
}
 
开发者ID:AdyoOrg,项目名称:adyo-android,代码行数:9,代码来源:AdyoRestRequest.java

示例14: linkUnix

import java.io.InputStreamReader; //导入方法依赖的package包/类
private void linkUnix() throws IOException {
    File so = new File(getDataFolder(), "ChocoTest.so");
    if(!so.exists()) {
        FileWriter wr = new FileWriter(so);
        InputStreamReader in = new InputStreamReader(this.getClass().getResourceAsStream("ChocoTest.so"));
        int i;
        while((i = in.read()) != -1) {
            wr.write(i);
        }
    }
    System.load(so.getAbsolutePath());
}
 
开发者ID:Redrield,项目名称:SpigotNativePlugin,代码行数:13,代码来源:ChocoTest.java

示例15: streamToString

import java.io.InputStreamReader; //导入方法依赖的package包/类
protected String streamToString(InputStream is) throws Exception
{
    String encoding = mTextEncoding;
    if (encoding == null) {
        encoding = mHeaderEncoding;
        if (encoding == null) {
            //Use the default encoding. This is not very optimal, but there is not
            //much that can be done about it.
            encoding = DEFAULT_ENCODING;    
        }
    }
    
    //Try to preallocate the string builder. It is ok if this is huge, we will
    //probably get an out of memory exception and fail gracefully.
    int sizeHint = (int)mContentLength;
    if (sizeHint < 0) {
        sizeHint = 1024;
    }
    
    char[] buffer = new char[BUFFER_SIZE];
    InputStreamReader reader = new InputStreamReader(is, encoding);
    StringBuilder result = new StringBuilder(sizeHint);
    
    int count = 0;
    while ((count = reader.read(buffer, 0, buffer.length)) >= 0) {
        result.append(buffer, 0, count);
    }
    return result.toString();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:30,代码来源:TextTask.java


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