List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:bixo.examples.crawl.RegexUrlFilter.java
public static List<String> getDefaultUrlFilterPatterns() throws IOException { InputStream is = RegexUrlFilter.class.getResourceAsStream("/regex-url-filters.txt"); DataInputStream in = new DataInputStream(is); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); return readFilters(reader); }
From source file:cc.redberry.core.tensor.BulkTestsForParser.java
private static void testParseRecurrently(File file, Counter containsParseLinesCounter, Counter matchedLinesCounter, DescriptiveStatistics statistics) { if (file.isFile()) { if (file.getName().equals(BulkTestsForParser.class.getSimpleName() + ".java")) return; if (file.getName().equals(ParserTest.class.getSimpleName() + ".java")) return; if (file.getName().equals(NumberParserTest.class.getSimpleName() + ".java")) return; FileInputStream fileInputStream; try {/*from www. j av a2s . com*/ fileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { throw new RuntimeException(); } DataInputStream dataInputStream = new DataInputStream(fileInputStream); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataInputStream)); String string; try { boolean containsParse; boolean matchedParse; int lineNumber = -1; String bufferedString = null; while ((string = bufferedReader.readLine()) != null) { ++lineNumber; if (bufferedString != null) { string = bufferedString + "\n" + string; bufferedString = null; } matchedParse = false; if (string.contains("IndexMappingTestUtils.parse") || string.contains("ParserIndices.parse")) continue; containsParse = (string.contains("parse(") || string.contains("parseExpression(") || string.contains("parseSimple(")) && string.contains("\""); string = string.trim(); if (string.length() > 0) { char c = string.charAt(string.length() - 1); if (c == '\"' || c == '+' || c == '(') { bufferedString = string; continue; } } string = string.replaceAll("\n", ""); string = string.replaceAll("\"[\\s]*\\+[\\+]*[\\s]*\"", ""); Matcher matcher = pattern.matcher(string); String tensorString; Tensor tensor; while (matcher.find()) { matchedParse = true; tensorString = matcher.group(2); //if (tensorString.length() > 100) // System.out.println("\"" + tensorString + "\","); tensorString = tensorString.replace("\\\\", "\\"); if (tensorString.contains("\"")) { tensorString = tensorString.split("\"")[0]; } try { statistics.addValue(tensorString.length()); tensor = Tensors.parse(tensorString); checkTensor(tensor); } catch (AssertionError | RuntimeException e) { System.out.println(e.getClass().getSimpleName() + ":"); System.out.println(tensorString); System.out.println(file + " line: " + lineNumber); System.out.println(); throw new RuntimeException(e); } } if (containsParse && !matchedParse && bufferedString == null) { System.out.println("Parse but not matched:"); System.out.println(string); System.out.println(file + " line: " + lineNumber); System.out.println(); } if (containsParse && bufferedString == null) containsParseLinesCounter.increase(); if (matchedParse) matchedLinesCounter.increase(); } bufferedReader.close(); dataInputStream.close(); } catch (IOException e) { throw new RuntimeException(); } } else if (file.isDirectory()) { File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { for (int i = 0; i < listOfFiles.length; i++) testParseRecurrently(listOfFiles[i], containsParseLinesCounter, matchedLinesCounter, statistics); } } else throw new RuntimeException(); }
From source file:com.maverick.ssl.SSLTransportImpl.java
public void initialize(InputStream in, OutputStream out, SSLContext context) throws IOException, SSLException { this.rawIn = new DataInputStream(in); this.rawOut = new DataOutputStream(out); writeCipherSuite = readCipherSuite = new SSL_NULL_WITH_NULL_NULL(); // #ifdef DEBUG log.debug(Messages.getString("SSLTransport.initialising")); //$NON-NLS-1$ // #endif//ww w . jav a2s .c om if (context == null) context = new SSLContext(); handshake = new SSLHandshakeProtocol(this, context); // Start the handshake handshake.startHandshake(); // While the handshake is not complete process all the messages while (!handshake.isComplete()) { processMessages(); // #ifdef DEBUG log.debug(Messages.getString("SSLTransport.initCompleteStartingAppProtocol")); //$NON-NLS-1$ // #endif } }
From source file:de.hybris.platform.jobs.RemovedItemPKProcessorTest.java
@Test public void testSkipofDeletedAndRefused() { final PK one = PK.createFixedUUIDPK(102, 1); final PK two = PK.createFixedUUIDPK(102, 2); final PK three = PK.createFixedUUIDPK(102, 3); final MediaModel mediaPk = new MediaModel(); final DataInputStream dis = new DataInputStream(buildUpStream(one, two, three)); Mockito.when(model.getItemPKs()).thenReturn(mediaPk); Mockito.when(mediaService.getStreamFromMedia(mediaPk)).thenReturn(dis); Mockito.when(model.getItemsRefused()).thenReturn(Integer.valueOf(2)); Mockito.when(model.getItemsDeleted()).thenReturn(Integer.valueOf(2)); iterator.init(model);//from w w w. j ava2s . com Assert.assertFalse("All iterations should be skipped ", iterator.hasNext()); }
From source file:com.cloudera.dataflow.hadoop.WritableCoder.java
@Override public T decode(InputStream inStream, Context context) throws IOException { try {/*from w w w.ja va 2 s. c o m*/ T t = type.getConstructor().newInstance(); t.readFields(new DataInputStream(inStream)); return t; } catch (NoSuchMethodException | InstantiationException | IllegalAccessException e) { throw new CoderException("unable to deserialize record", e); } catch (InvocationTargetException ite) { throw new CoderException("unable to deserialize record", ite.getCause()); } }
From source file:com.athena.chameleon.engine.threadpool.task.BaseTask.java
/** * <pre>/*w w w .j a v a 2s .c o m*/ * ?? ? ? . * </pre> * @param file * @return */ protected String fileToString(String file) { String result = null; try { DataInputStream in = null; File f = new File(file); byte[] buffer = new byte[(int) f.length()]; in = new DataInputStream(new FileInputStream(f)); in.readFully(buffer); result = new String(buffer); IOUtils.closeQuietly(in); } catch (IOException e) { throw new RuntimeException("IO problem in fileToString", e); } return result; }
From source file:com.google.cloud.dataflow.sdk.io.hdfs.WritableCoder.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2 s . c om*/ public T decode(InputStream inStream, Context context) throws IOException { try { if (type == NullWritable.class) { // NullWritable has no default constructor return (T) NullWritable.get(); } T t = type.newInstance(); t.readFields(new DataInputStream(inStream)); return t; } catch (InstantiationException | IllegalAccessException e) { throw new CoderException("unable to deserialize record", e); } }
From source file:edu.gmu.csiss.automation.pacs.utils.BaseTool.java
/** * Read the string from a file//from ww w . j ava 2s. c o m * @param path * @return */ public static String readStringFromFile(String path) { StringBuffer strLine = new StringBuffer(); try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(path); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); FileReader fr = new FileReader(path); BufferedReader br = new BufferedReader(fr); String str = null; //Read File Line By Line while ((str = br.readLine()) != null) { // Print the content on the console strLine.append(str).append("\n"); // System.out.println (strLine); } //Close the input stream in.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } return strLine.toString().trim(); }
From source file:edu.udel.mxv.MxvMap.java
@Override protected void setup(Mapper<LongWritable, Text, IntWritable, DoubleWritable>.Context context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); String input_vector = conf.get("vector.path"); x_i = new double[conf.getInt("vector.n", 0)]; FileSystem fs = FileSystem.get(URI.create(input_vector), conf); FileStatus[] status = fs.listStatus(new Path(input_vector)); for (int i = 0; i < status.length; ++i) { Path file = status[i].getPath(); System.out.println("status: " + i + " " + file.toString()); DataInputStream dis = new DataInputStream(fs.open(file)); String line = null;// w w w.jav a 2 s . co m int count = 0; while ((line = dis.readLine()) != null) { String[] split_line = line.split(","); if (split_line.length == 2) { int pos = Integer.parseInt(split_line[0]); double val = Double.parseDouble(split_line[1]); x_i[pos++] = val; count++; } else LOG.error("Parse error in line: " + line); } LOG.info("Number of elements read for vector = " + count); } }
From source file:RMSGameScores.java
public boolean matches(byte[] candidate) throws IllegalArgumentException { // If no filter set, nothing can match it. if (this.playerNameFilter == null) { return false; }//from ww w .j av a 2s. co m ByteArrayInputStream bais = new ByteArrayInputStream(candidate); DataInputStream inputStream = new DataInputStream(bais); String name = null; try { int score = inputStream.readInt(); name = inputStream.readUTF(); } catch (EOFException eofe) { System.out.println(eofe); eofe.printStackTrace(); } catch (IOException eofe) { System.out.println(eofe); eofe.printStackTrace(); } return (this.playerNameFilter.equals(name)); }