List of usage examples for java.io EOFException printStackTrace
public void printStackTrace()
From source file:org.apache.hadoop.hbase.rest.TestTableScan.java
/** * Read protobuf stream./*from w ww . ja v a 2 s. c o m*/ * @param inputStream the input stream * @return The number of rows in the cell set model. * @throws IOException Signals that an I/O exception has occurred. */ public int readProtobufStream(InputStream inputStream) throws IOException { DataInputStream stream = new DataInputStream(inputStream); CellSetModel model = null; int rowCount = 0; try { while (true) { byte[] lengthBytes = new byte[2]; int readBytes = stream.read(lengthBytes); if (readBytes == -1) { break; } assertEquals(2, readBytes); int length = Bytes.toShort(lengthBytes); byte[] cellset = new byte[length]; stream.read(cellset); model = new CellSetModel(); model.getObjectFromMessage(cellset); checkRowsNotNull(model); rowCount = rowCount + TestScannerResource.countCellSet(model); } } catch (EOFException exp) { exp.printStackTrace(); } finally { stream.close(); } return rowCount; }
From source file:com.cohesionforce.dis.BinaryConverter.java
public void run() { int count = 0; System.out.println("Opening file to convert: " + inputFile); FileInputStream fis;// w w w . j a v a 2 s . co m try { fis = new FileInputStream(inputFile); } catch (FileNotFoundException e1) { e1.printStackTrace(); return; } DataInputStream dis = new DataInputStream(fis); startWriters(); System.out.println("Starting to convert PDUs"); while (done == false) { byte buffer[] = new byte[MAX_PDU_SIZE]; byte pduType; try { pduType = dis.readByte(); int pduSize = dis.readInt(); int skip = dis.read(buffer, 0, 19); assert (skip == 19); int numberRead = dis.read(buffer, 0, pduSize); assert (numberRead == pduSize); ++count; // Convert the byte array to an object Object object; object = unmarshaller.getPdu(buffer); if (object != null) { logPdu(object, pduType); } } catch (EOFException e) { done = true; } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { done = true; e.printStackTrace(); } if (count % 100000 == 0) { System.out.println("Converted " + count + " PDUs"); } } // end loop try { dis.close(); } catch (IOException e1) { e1.printStackTrace(); } System.out.print("Waiting on writers to clear their queues"); boolean emptyQueue = false; while (!emptyQueue) { emptyQueue = true; for (LogWriter<?> writer : writers) { // If any queue is not empty, sleep and check again if (!writer.getQueue().isEmpty()) { try { emptyQueue = false; System.out.print("."); Thread.sleep(1000); break; } catch (InterruptedException e) { e.printStackTrace(); } } } } System.out.println(""); System.out.println("PDUs converted: " + count); System.out.println("Shutting down logging threads"); threadGroup.interrupt(); int tries = 0; while (threadGroup.activeCount() > 0 && tries < 10) { try { Thread.sleep(2000); } catch (InterruptedException e) { } ++tries; } System.out.println("Completed logging threads shutdown"); }
From source file:com.alphabetbloc.accessmrs.services.SyncManager.java
public String readObsFile(File tempFile, SyncResult syncResult) { if (tempFile == null) return "error"; try {// www . j a v a 2 s . c o m DataInputStream dis = new DataInputStream(new FileInputStream(tempFile)); if (dis != null) { DbProvider dbHelper = DbProvider.openDb(); // open db and clean entries dbHelper.delete(DataModel.PATIENTS_TABLE, DataModel.KEY_CLIENT_CREATED + " IS NULL", null); dbHelper.delete(DataModel.OBSERVATIONS_TABLE, null, null); insertPatients(dis); addSyncStep(mContext.getString(R.string.sync_updating_data), false); // 70% insertObservations(dis); try { addSyncStep(mContext.getString(R.string.sync_updating_data), false); // 90% // (doubled // due // to // slow // speed) insertPatientForms(dis); } catch (EOFException e) { // do nothing for EOFExceptions in this case if (App.DEBUG) Log.v(TAG, "No SmartForms available on server"); } dis.close(); } updateAccessMrsObs(); addSyncStep(mContext.getString(R.string.sync_updating_data), false); // 100% } catch (Exception e) { e.printStackTrace(); ++syncResult.stats.numIoExceptions; return e.getLocalizedMessage(); } return null; }
From source file:henplus.HenPlus.java
public void run() { String cmdLine = null;//from w ww . jav a2s . co m String displayPrompt = _prompt; while (!_terminated) { _interrupted = false; /* * a CTRL-C will not interrupt the current reading thus it does not * make much sense here to interrupt. WORKAROUND: Print message in * the interrupt() method. TODO: find out, if we can do something * that behaves like a shell. This requires, that CTRL-C makes * Readline.readline() return.. */ SigIntHandler.getInstance().pushInterruptable(this); try { cmdLine = _fromTerminal ? Readline.readline(displayPrompt, false) : readlineFromFile(); } catch (final EOFException e) { // EOF on CTRL-D if (_sessionManager.getCurrentSession() != null) { _dispatcher.execute(_sessionManager.getCurrentSession(), "disconnect"); displayPrompt = _prompt; continue; } else { break; // last session closed -> exit. } } catch (final Exception e) { if (_verbose) { e.printStackTrace(); } } SigIntHandler.getInstance().reset(); // anyone pressed CTRL-C if (_interrupted) { _historyLine.setLength(0); _commandSeparator.discard(); displayPrompt = _prompt; continue; } if (cmdLine == null) { continue; } /* * if there is already some line in the history, then add newline. * But if the only thing we added was a delimiter (';'), then this * would be annoying. */ if (_historyLine.length() > 0 && !cmdLine.trim().equals(";")) { _historyLine.append("\n"); } _historyLine.append(cmdLine); final byte lineExecState = executeLine(cmdLine); if (lineExecState == LINE_INCOMPLETE) { displayPrompt = _emptyPrompt; } else { displayPrompt = _prompt; } if (lineExecState != LINE_INCOMPLETE) { storeLineInHistory(); } } SigIntHandler.getInstance().reset(); }
From source file:TalkServerThread.java
public void run() { while (socket != null) { try {//www. ja v a 2s. c o m //Read data. String str = is.readLine(); //Pass it on. if (str != null) { server.forwardString(str, this); } } catch (EOFException e) { //No more data on this socket... server.forwardString("SERVER SAYS other applet disconnected", this); cleanup(); return; } catch (NullPointerException e) { //Socket doesn't exist... server.forwardString("SERVER SAYS no socket to other applet", this); cleanup(); return; } catch (IOException e) { //Read problem.. server.forwardString("SERVER SAYS socket trouble with other applet", this); cleanup(); return; } catch (Exception e) { //Unknown exception. Complain and quit. System.err.println("Exception on is.readLine():"); e.printStackTrace(); cleanup(); return; } } }
From source file:com.marklogic.mapreduce.test.FCheck.java
public void decodeTreeData(File dir) throws IOException { File file = new File(dir, "TreeData"); // LSSerializer writer; // LSOutput lsout; // try { //// DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); //// DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("XML 3.0"); //// writer = impl.createLSSerializer(); // //writer.getDomConfig().setParameter("canonical-form", "true"); // lsout = impl.createLSOutput(); // lsout.setCharacterStream(new PrintWriter(System.out)); // lsout.setEncoding("UTF-8"); // }//from w w w .j a v a 2 s . c o m // catch (Exception e) { // throw new RuntimeException("Unable to initialize XML serialization.", e); // } if (verbose) System.out.println(file.getAbsolutePath() + " -> checkTreeData"); treeDataSize = file.length(); BiendianDataInputStream in = openFile(file, 1 << 18); int position = 0; int docid, csword, checksum, datWords, fdatw, hdrWords = 2, j; long prevDocid = -1; for (;; ++position) { try { docid = in.readInt(); csword = in.readInt(); fdatw = in.readInt(); checksum = csword & 0xfffffff0; datWords = csword & 0x0000000f; if (datWords == 0) { datWords = fdatw; hdrWords = 3; System.out.println("3 header words"); } if (docid == 0xffffffff && csword == 0xffffffff && fdatw == 0xffffffff) { System.out.println("Reached the end."); break; } if (prevDocid != -1 && docid <= prevDocid) { panic(file, "docid out of order, position=" + position + ", docid=" + docid + ", prevDocid=" + prevDocid); } prevDocid = docid; if (hdrWords == 2) { j = datWords - 1; } else { j = datWords; } j *= 4; } catch (EOFException e) { break; } if (debug) { System.out.println(String.format("\n\nTreeData p %d d %d c %016x", position, docid, checksum)); } System.out.println("POSITION " + position); System.out.println("docid=" + docid + " datWords=" + datWords); try { // in.setLittleEndian(false); in.getInputStream().mark(j); // TODO: Is it better to read into a buffer or directly from the // stream then reset and skip? byte[] buf = new byte[j]; for (int read = 0; read < j;) { read += in.read(buf, read, j - read); } ExpandedTree tree = new CompressedTreeDecoder().decode(buf, j); // TODO: count and verify bytes read // int computed = computeChecksum(docid, in, datWords); System.out.println(tree.getDocumentURI()); byte kind = tree.rootNodeKind(); if (kind == NodeKind.BINARY) { System.out.println("binary root"); } else if (kind == NodeKind.ELEM) { System.out.println("element root"); } else if (kind == NodeKind.TEXT) { System.out.println("text root"); } else { System.out.println("unexpected node kind: " + kind); } if (kind != NodeKind.BINARY) { Node root = tree.node(0); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DomUtil.writeXml(root, bos); System.out.println(bos.toString()); } } catch (Exception e) { System.err.println("Fail at position " + position); e.printStackTrace(); } in.getInputStream().reset(); while (j > 0) { long actual = in.getInputStream().skip(j); if (actual < j) { j -= actual; } else if (actual > j) { panic(file, "Over-skipped: actual=" + actual + ",j=" + j); } else { break; } } } if (verbose) System.out.println(file.getAbsolutePath() + " <- checkTreeData [" + position + "]"); }
From source file:playground.sergioo.workplaceCapacities2012.MainWorkplaceCapacities.java
private static void calculateOptimizationParameters() throws BadStopException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, NoConnectionException { System.out.println("Process starts with " + SIZE + " clusters and " + NUM_ITERATIONS + " iterations."); /*CoordinateTransformation coordinateTransformation = TransformationFactory.getCoordinateTransformation(TransformationFactory.WGS84, TransformationFactory.WGS84_UTM48N); downLeft=coordinateTransformation.transform(downLeft); upRight=coordinateTransformation.transform(upRight);*/ Map<Id<TransitStopFacility>, Double> stopCapacities = new HashMap<Id<TransitStopFacility>, Double>(); Map<String, Double> quantitiesMap; try {// w ww . j a va 2s . c o m ObjectInputStream ois = new ObjectInputStream(new FileInputStream(QUANTITIES_MAP_FILE)); quantitiesMap = (Map<String, Double>) ois.readObject(); stopCapacities = (Map<Id<TransitStopFacility>, Double>) ois.readObject(); ois.close(); } catch (EOFException e) { quantitiesMap = calculateStopClustersQuantities(stopCapacities); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(QUANTITIES_MAP_FILE)); oos.writeObject(quantitiesMap); oos.writeObject(stopCapacities); oos.close(); } MatrixND<Double> quantities = new Matrix2DImpl(new int[] { clusters.size(), stopsBase.size() }); stopScheduleCapacities = new ArrayList<List<Double>>(); Iterator<String> stopIdsI = stopsBase.keySet().iterator(); //Iterator<Coord> stopsI = stopsBase.values().iterator(); for (int s = 0; s < quantities.getDimension(1); s++) { String stopId = stopIdsI.next(); /*Coord stopCoord = stopsI.next(); boolean inStop = stopCoord.getX()>downLeft.getX() && stopCoord.getX()<upRight.getX() && stopCoord.getY()>downLeft.getY() && stopCoord.getY()<upRight.getY(); if(inStop)*/ stopScheduleCapacities.add(new ArrayList<Double>()); for (int c = 0; c < quantities.getDimension(0); c++) { Double quantity = quantitiesMap.get(stopId + SEPARATOR + c); if (quantity == null) quantity = 0.0; quantities.setElement(new int[] { c, s }, quantity); //if(inStop) stopScheduleCapacities.get(stopScheduleCapacities.size() - 1).add(quantity); } } System.out.println("Quantities done!"); MatrixND<Double> maxs = new Matrix1DImpl(new int[] { dataMPAreas.size() }, 60.0); Iterator<Id<ActivityFacility>> mPAreaI = dataMPAreas.keySet().iterator(); maximumAreaCapacities = new TreeMap<Id<ActivityFacility>, Double>(); for (int f = 0; f < maxs.getDimension(0); f++) { Id<ActivityFacility> mPId = mPAreaI.next(); MPAreaData dataMPArea = dataMPAreas.get(mPId); double max = getMaxCapacity(dataMPArea) * dataMPArea.getModeShare() / (1 + dataMPArea.getModeShare()); maxs.setElement(new int[] { f }, max); Coord areaCoord = dataMPArea.getCoord(); if (areaCoord.getX() > downLeft.getX() && areaCoord.getX() < upRight.getX() && areaCoord.getY() > downLeft.getY() && areaCoord.getY() < upRight.getY()) maximumAreaCapacities.put(mPId, max); } System.out.println("Max areas done!"); Map<Tuple<Id<TransitStopFacility>, Id<ActivityFacility>>, Tuple<Boolean, Double>> weightsMap; try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(WEIGHTS_MAP_FILE)); weightsMap = (Map<Tuple<Id<TransitStopFacility>, Id<ActivityFacility>>, Tuple<Boolean, Double>>) ois .readObject(); ois.close(); try { ois = new ObjectInputStream(new FileInputStream(TRAVEL_TIMES_FILE)); travelTimes = (List<List<Double>>) ois.readObject(); ois.close(); } catch (EOFException e) { e.printStackTrace(); } } catch (EOFException e) { weightsMap = calculateAreaStopTravelTimes(stopsBase, stopCapacities, network); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(WEIGHTS_MAP_FILE)); oos.writeObject(weightsMap); oos.close(); oos = new ObjectOutputStream(new FileOutputStream(TRAVEL_TIMES_FILE)); oos.writeObject(travelTimes); oos.close(); } /*Map<Integer, Double> tts = new HashMap<Integer, Double>(); for(int i=0; i<travelTimes.size(); i++) if(travelTimes.get(i).get(8134)<36000) tts.put(i, travelTimes.get(i).get(8134));*/ new WeigthsNetworkWindow("Weights", new NetworkPainter(network), weightsMap, dataMPAreas, stopsBase) .setVisible(true); System.out.println("Travel times done!"); /*Matrix2DImpl weights = new Matrix2DImpl(new int[]{dataMPAreas.size(),stopsBase.size()}); mPAreaI = dataMPAreas.keySet().iterator(); for(int f=0; f<weights.getDimension(0); f++) { Id<ActivityFacility> mPAreaId = mPAreaI.next(); stopIdsI = stopsBase.keySet().iterator(); for(int s=0; s<weights.getDimension(1); s++) { Id<TransitStopFacility> sId = Id.create(stopIdsI.next(), TransitStopFacility.class); Tuple<Boolean, Double> weight = weightsMap.get(new Tuple<Id<TransitStopFacility>, Id<ActivityFacility>>(sId, mPAreaId)); if(weight==null) weights.setElement(f, s, 0.0); else weights.setElement(f, s, weight.getSecond()); } }*/ System.out.println("Weights done!"); Matrix2DImpl proportions = new Matrix2DImpl(new int[] { dataMPAreas.size(), clusters.size() }); Map<String, List<Double>> proportionsMap = calculateTypeBuildingOptionWeights(clusters); mPAreaI = dataMPAreas.keySet().iterator(); for (int f = 0; f < proportions.getDimension(0); f++) { Id<ActivityFacility> mPAreaId = mPAreaI.next(); for (int c = 0; c < proportions.getDimension(1); c++) proportions.setElement(f, c, proportionsMap.get(dataMPAreas.get(mPAreaId).getType()).get(c)); } System.out.println("Proportions done!"); writeOptimizationParameters(); }