public void run(String local, String remote, InputStream pin, OutputStream pout) { try { microphone = SoundMixerEnumerator.getInputLine(pcmformat, DefaultPhonePCMBlockSize); } catch (LineUnavailableException lue) { System.out.println( "\3b" + getClass().getName() + ".<init>:\n\tCould not create microphone input stream.\n\t" + lue); } try { speaker = SoundMixerEnumerator.getOutputLine(pcmformat, DefaultPhonePCMBlockSize); } catch (LineUnavailableException lue) { microphone.close(); System.out.println( "\3b" + getClass().getName() + ".<init>:\n\tCould not create speaker output stream.\n\t" + lue); } if ((speaker == null) || (microphone == null)) { super.run(local, remote, pin, pout); return; } try { recorder = new Recorder(pout); recorder.start(); gui = openMonitorGUI("Remote " + remote + " Local " + local); pin.skip(pin.available()); // waste whatever we couldn't process in time super.run(local, remote, new PhoneCallMonitorInputStream(pin), pout); recorder.interrupt(); gui.dispose(); } catch (Exception e) { System.out.println("3\b" + getClass().getName() + ".run:\n\t" + e); e.printStackTrace(); } finally { deactivate(); microphone.close(); speaker.close(); if (gui != null) { gui.dispose(); } } }
public void replace(String file) throws FileNotFoundException, IOException { InputStream inputStream = new FileInputStream(file); Reader r = new BufferedReader(new InputStreamReader(inputStream)); VRML97ProtoTokenizer st = new VRML97ProtoTokenizer(r); replace(st); inputStream.close(); }
/** Loads the resources */ void initResources() { final Class<ControlExample> clazz = ControlExample.class; if (resourceBundle != null) { try { if (images == null) { images = new Image[imageLocations.length]; for (int i = 0; i < imageLocations.length; ++i) { InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]); ImageData source = new ImageData(sourceStream); if (imageTypes[i] == SWT.ICON) { ImageData mask = source.getTransparencyMask(); images[i] = new Image(null, source, mask); } else { images[i] = new Image(null, source); } try { sourceStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return; } catch (Throwable t) { } } String error = (resourceBundle != null) ? getResourceString("error.CouldNotLoadResources") : "Unable to load resources"; //$NON-NLS-1$ freeResources(); throw new RuntimeException(error); }
public void run() { try { Socket s = serverSock.accept(); InputStream in = s.getInputStream(); byte b[] = new byte[4096]; // assume we read the entire http request // (bad assumption but okay for test case) int nread = in.read(b); // check the date format by the position of the comma String request = new String(b, 0, nread); int pos = request.indexOf("If-Modified-Since:"); int respCode = 200; if (pos != -1) { pos += "If-Modified-Since:".length() + 4; if (pos < nread) { if (request.charAt(pos) == (char) ',') { respCode = 304; } } } OutputStream o = s.getOutputStream(); if (respCode == 304) { o.write("HTTP/1.1 304 Not Modified".getBytes()); } else { o.write("HTTP/1.1 200 OK".getBytes()); } o.write((byte) '\r'); o.write((byte) '\n'); o.write((byte) '\r'); o.write((byte) '\n'); o.flush(); } catch (Exception e) { } }
public void run(String arg) { GenericDialog gd = new GenericDialog("Options"); double sfreq = 20000.0; gd.addNumericField("Sampling Frequency?", sfreq, 1, 10, null); String[] psfchoice = {"3D Gaussian", "Gaus-Lorentz^2", "2D Gaussian"}; gd.addChoice("PSF Type?", psfchoice, psfchoice[0]); String[] filetypechoice = { "Confocor 3 raw", "Short binary trajectory", "PlotWindow trajectory", "Ascii Text File" }; gd.addChoice("File Type?", filetypechoice, filetypechoice[0]); boolean ch2green = true; gd.addCheckbox("Ch2 is green?", ch2green); gd.showDialog(); if (gd.wasCanceled()) { return; } sfreq = gd.getNextNumber(); int psfflag = gd.getNextChoiceIndex(); int fileflag = gd.getNextChoiceIndex(); ch2green = gd.getNextBoolean(); int nfiles = 0; Object[] histograms = null; int xmax = 0; int ymax = 0; String[] names = null; if (fileflag < 2) { jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length / 2; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = organize_c3_files(filearray); for (int i = 0; i < nfiles; i++) { try { int length1 = (int) (((double) filearray[2 * i].length() - 128.0) / 4.0); int length2 = (int) (((double) filearray[2 * i + 1].length() - 128.0) / 4.0); int length3 = (int) (((double) filearray[2 * i].length()) / 2.0); int length4 = (int) (((double) filearray[2 * i + 1].length()) / 2.0); InputStream instream = new BufferedInputStream(new FileInputStream(filearray[2 * i])); InputStream instream2 = new BufferedInputStream(new FileInputStream(filearray[2 * i + 1])); if (fileflag == 0) { int[] pmdata = new int[length1]; int[] pmdata2 = new int[length2]; if (!ioclass.skipstreambytes(instream, 128)) { showioerror(); instream.close(); return; } if (!ioclass.skipstreambytes(instream2, 128)) { showioerror(); instream2.close(); return; } if (!ioclass.readintelintfile(instream, length1, pmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelintfile(instream2, length2, pmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).pm2pch(pmdata2, pmdata, sfreq, 20000000); } else { histograms[i] = (new pmodeconvert()).pm2pch(pmdata, pmdata2, sfreq, 20000000); } } else { float[] tmdata = new float[length3]; float[] tmdata2 = new float[length4]; if (!ioclass.readintelshortfile(instream, length3, tmdata)) { showioerror(); instream.close(); return; } if (!ioclass.readintelshortfile(instream2, length4, tmdata2)) { showioerror(); instream2.close(); return; } if (ch2green) { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata2, tmdata); } else { histograms[i] = (new pmodeconvert()).create_2Dhistogram(tmdata, tmdata2); } } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } instream.close(); instream2.close(); } catch (IOException e) { showioerror(); return; } } } else { if (fileflag == 2) { ImageWindow iw = WindowManager.getCurrentWindow(); float[][] trajectories = (float[][]) jutils.runPW4VoidMethod(iw, "getYValues"); float[][] tempxvals = (float[][]) jutils.runPW4VoidMethod(iw, "getXValues"); sfreq = 1.0 / ((double) tempxvals[0][1]); nfiles = trajectories.length / 2; if (nfiles > 25) { nfiles = 25; } names = new String[nfiles + 1]; names[nfiles] = "avg"; histograms = new Object[nfiles]; for (int i = 0; i < nfiles; i++) { names[i] = "trajectory " + (i + 1); if (ch2green) { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i + 1], trajectories[2 * i]); } else { histograms[i] = (new pmodeconvert()) .create_2Dhistogram(trajectories[2 * i], trajectories[2 * i + 1]); } if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } else { // here we read tab delimited lines from files jdataio ioclass = new jdataio(); File[] filearray = ioclass.openfiles(OpenDialog.getDefaultDirectory(), IJ.getInstance()); if (filearray.length == 0) { return; } String dir = filearray[0].getAbsolutePath(); int sepindex = dir.lastIndexOf(File.separator); String newdir = dir.substring(0, sepindex + 1); OpenDialog.setDefaultDirectory(newdir); nfiles = filearray.length; if (nfiles > 25) { nfiles = 25; } histograms = new Object[nfiles]; names = new String[nfiles + 1]; names[nfiles] = "avg"; for (int i = 0; i < nfiles; i++) { try { names[i] = filearray[i].getName(); BufferedReader d = new BufferedReader(new FileReader(filearray[i])); String[] lines = new String[256]; int counter = 0; do { lines[counter] = d.readLine(); counter++; } while ((lines[counter - 1] != null && lines[counter - 1] != "") && counter < 256); int numcolumns = 0; for (int j = 0; j < counter - 1; j++) { int temp = getncolumns(lines[j]); if (temp > numcolumns) { numcolumns = temp; } } float[][] temphist2 = null; if (ch2green) { temphist2 = new float[numcolumns][counter - 1]; } else { temphist2 = new float[counter - 1][numcolumns]; } for (int k = 0; k < counter - 1; k++) { float[] temp = tab_delim2float(lines[k]); for (int j = 0; j < numcolumns; j++) { if (ch2green) { temphist2[j][k] = temp[j]; } else { temphist2[k][j] = temp[j]; } } } histograms[i] = temphist2; d.close(); } catch (IOException e) { showioerror(); return; } } for (int i = 0; i < nfiles; i++) { if (((float[][]) histograms[i]).length > xmax) { xmax = ((float[][]) histograms[i]).length; } if (((float[][]) histograms[i])[0].length > ymax) { ymax = ((float[][]) histograms[i])[0].length; } } } } // note that here x is green and y is red float[][][] pch = new float[nfiles][xmax][ymax]; for (int i = 0; i < nfiles; i++) { for (int j = 0; j < ((float[][]) histograms[i]).length; j++) { for (int k = 0; k < ((float[][]) histograms[i])[j].length; k++) { pch[i][j][k] = ((float[][]) histograms[i])[j][k]; } } } final PCH2DFitWindow cw = new PCH2DFitWindow(); cw.init(names, pch, psfflag); final Frame f = new Frame("PCH 2D Analysis"); f.setLocation(10, 10); f.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { f.dispose(); } }); f.add(cw); f.pack(); f.setResizable(false); Insets ins = f.getInsets(); cw.totalSize.height = PCH2DFitWindow.H + ins.bottom + ins.top + 65; cw.totalSize.width = PCH2DFitWindow.WR + ins.left + ins.right; f.setSize(cw.totalSize); f.setVisible(true); cw.requestFocus(); }
/** * Copies all data from in to out * * @param in the input stream * @param out the output stream * @param buffer copy buffer */ public static void copyStreamsWithoutClose(InputStream in, OutputStream out, byte[] buffer) throws IOException { int b; while ((b = in.read(buffer)) != -1) out.write(buffer, 0, b); }
/** * Copies all data from in to out * * @param in the input stream * @param out the output stream * @param buffer copy buffer */ public static void copyStreams(InputStream in, OutputStream out, byte[] buffer) throws IOException { copyStreamsWithoutClose(in, out, buffer); in.close(); out.close(); }
public void close() throws IOException { if (mInputStream == null) throw new IOException(getTempFilename()); mInputStream.close(); }