private void onOK() { try { InputStream in = new FileInputStream(inputFile); if (outputFile == null) { outputFile = new File(inputFile.getAbsolutePath() + "_"); } OutputStream out = new FileOutputStream(outputFile); ANSIUnicodeConverter converter = new ANSIUnicodeConverter(); converter.setDirection(ANSIUnicodeConverter.ANSI2UNICODE); StringBuffer output = new StringBuffer(); final int BUFFER_SIZE = 1024 * 1024; // 1M byte[] buffer = new byte[BUFFER_SIZE]; int currentPosition = 0; while (in.available() != 0) { int currentBufferSize = BUFFER_SIZE; if (in.available() < BUFFER_SIZE) { currentBufferSize = in.available(); } in.read(buffer, currentPosition, currentBufferSize); currentBufferSize = currentBufferSize + currentBufferSize; converter.setInput(new String(buffer)); out.write(converter.convert().getBytes()); } in.close(); out.close(); } catch (Exception e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
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(); } } }
Ps2RealityControlCenter(String dir) throws IOException { try { byte[] abIcon; InputStream inputstreamIcon = this.getClass().getResourceAsStream("icon.gif"); int iIconSize = inputstreamIcon.available(); abIcon = new byte[iIconSize]; inputstreamIcon.read(abIcon); this.setIconImage(new ImageIcon(abIcon).getImage()); } catch (Exception ex) { // the default icon will be used } panelChooser = new Ps2RealityFileChooser(dir); }
/** * Loads an image from a given image identifier. * * @param imageID The identifier of the image. * @return The image for the given identifier. */ @Override public byte[] getImageInBytes(String imageID) { InputStream in = getImageInputStream(imageID); if (in == null) return null; byte[] image = null; try { image = new byte[in.available()]; in.read(image); } catch (IOException e) { logger.error("Failed to load image:" + imageID, e); } return image; }
public void run() { try { final byte[] lBuf = new byte[1024]; int lBytesRead; while (in.read(lBuf, 0, 1) != -1) { synchronized (JConsole.this) { lBytesRead = in.read(lBuf, 1, 1023) + 1; print(new String(lBuf, 0, lBytesRead), attr); while (in.available() > 0) { lBytesRead = in.read(lBuf); print(new String(lBuf, 0, lBytesRead), attr); } } } } catch (IOException e) { e.printStackTrace(); } }