public String readResponse(HttpResponse response) { String output = ""; HttpEntity entity = response.getEntity(); try { trapException(response.getStatusLine().getStatusCode()); } catch (CrowdFlowerException e1) { e1.printStackTrace(); } InputStream instream; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response output = output + reader.readLine(); instream.close(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return output; }
public Requirement readRequirement(String xml) throws Exception { try { return readRequirement(new StringReader(xml)); } catch (IOException e) { IllegalStateException ex = new IllegalStateException(e); ex.initCause(e); throw ex; } }
public Property readProperty(String xml) throws Exception { try { return readProperty(new StringReader(xml)); } catch (IOException e) { IllegalStateException ex = new IllegalStateException(e); ex.initCause(e); throw ex; } }
public String writeResource(Resource resource) { try { StringWriter sw = new StringWriter(); writeResource(resource, sw); return sw.toString(); } catch (IOException e) { IllegalStateException ex = new IllegalStateException(e); ex.initCause(e); throw ex; } }
public String writeRequirement(Requirement requirement) { try { StringWriter sw = new StringWriter(); writeRequirement(requirement, sw); return sw.toString(); } catch (IOException e) { IllegalStateException ex = new IllegalStateException(e); ex.initCause(e); throw ex; } }
public String writeProperty(Property property) { try { StringWriter sw = new StringWriter(); writeProperty(property, sw); return sw.toString(); } catch (IOException e) { IllegalStateException ex = new IllegalStateException(e); ex.initCause(e); throw ex; } }
public String writeRepository(Repository repository) { try { StringWriter sw = new StringWriter(); writeRepository(repository, sw); return sw.toString(); } catch (IOException e) { IllegalStateException ex = new IllegalStateException(e); ex.initCause(e); throw ex; } }
public static void main(String[] args) throws Exception { System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); /** * This test does not establish any connection to the specified URL, hence a dummy URL is used. */ URL foobar = new URL("https://example.com/"); HttpsURLConnection urlc = (HttpsURLConnection) foobar.openConnection(); try { urlc.getCipherSuite(); } catch (IllegalStateException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.getServerCertificateChain(); } catch (IllegalStateException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setDefaultHostnameVerifier(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setHostnameVerifier(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setDefaultSSLSocketFactory(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception: "); System.out.println(e.getMessage()); } try { urlc.setSSLSocketFactory(null); } catch (IllegalArgumentException e) { System.out.print("Caught proper exception"); System.out.println(e.getMessage()); } System.out.println("TESTS PASSED"); }
public void exter_shutter_trigger() { try { shutter_trigger.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } shutter_trigger.start(); }
public void toClipBoard() { try { Toolkit.getDefaultToolkit() .getSystemClipboard() .setContents(new StringSelection(PArray.cat(M)), null); } catch (IllegalStateException e) { JOptionPane.showConfirmDialog( null, "Copy to clipboard failed : " + e.getMessage(), "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } }
public static HttpResponse doPost(String urlExtension, Map<String, String> parmas) { HttpResponse httpResponse = null; ArrayList<BasicNameValuePair> pairs = convertMapToNameValuePair(parmas); try { DefaultHttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(BASE_URL + urlExtension); UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(pairs, "utf-8"); httpPost.setEntity(p_entity); httpResponse = client.execute(httpPost); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return httpResponse; }
public void onShutter() { // TODO Auto-generated method stub AudioManager mgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mgr.setStreamMute(AudioManager.STREAM_SYSTEM, true); try { player.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } player.start(); }
public void play() { try { mp.setDataSource( Environment.getExternalStorageDirectory() + "/pathofthefile/" + FirstSettings_two.file_video); mp.prepare(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } mp.start(); }
@RequestMapping("/upfile") @ResponseBody public String upfile( @RequestParam("desc") String desc, @RequestParam("file") MultipartFile file) { try { if (!file.isEmpty()) { logger.info("{}上传中", desc); file.transferTo(new File("d:/fileupload/" + file.getOriginalFilename())); return "上传成功"; } } catch (IllegalStateException e) { logger.error("非法状态错误"); e.printStackTrace(); } catch (IOException e) { logger.error("文件I/O错误"); e.printStackTrace(); } return "上传失败"; }
// sends a response to the Client based upon the contents of the receive packet private void reply(DatagramPacket receivedPacket) { // verify the packet byte serverMsg[] = {}; try { Request recReq = new Request(receivedPacket.getData(), receivedPacket.getLength()); if (!recReq.isValid()) { throw new IllegalStateException(); } switch (recReq.getFormat()) { case RRQ: serverMsg = new byte[] {0, 3, 0, 1}; break; case WRQ: serverMsg = new byte[] {0, 4, 0, 0}; break; default: throw new IllegalStateException(); } } catch (IllegalStateException e) { e.printStackTrace(); System.exit(1); } DatagramPacket sendPacket = new DatagramPacket( serverMsg, serverMsg.length, receivedPacket.getAddress(), receivedPacket.getPort()); readSendPacket(sendPacket); try { // Send the datagram packet to the client via the send socket. DatagramSocket sendSocket = new DatagramSocket(); sendSocket.send(sendPacket); sendSocket.close(); } catch (SocketException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } System.out.println("Server: packet sent.\n"); }
public void exter_shutter_trigger_sec(double s) throws InterruptedException { try { shutter_trigger.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } int x = (int) ((s * 1000.0) / 100.0); for (int i = 0; i < x; i++) { // activity:message_inf(i,"第%03d張拍攝完成"); shutter_trigger.start(); while (shutter_trigger.isPlaying()) Thread.sleep(1); } }
@Override public void onCreate(Bundle savedInstanceState) { // System.loadLibrary("luajava-1.1"); // 設定橫向螢幕 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); this.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); this.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.registerReceiver(this.mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); L = LuaStateFactory.newLuaState(); L.pushJavaObject(this); L.setGlobal("activity"); res = getResources(); conf = res.getConfiguration(); conf.locale = Locale.TAIWAN; res.updateConfiguration(conf, null); super.onCreate(savedInstanceState); setContentView(R.layout.main); appobject = this.getApplicationContext(); surfaceView = (SurfaceView) findViewById(R.id.surfaceView1); surfaceHolder = surfaceView.getHolder(); surfaceHolder.addCallback(this); surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); //////////////////////////////////////////////////////////////////////////////////////////// /*bitmap2 = BitmapFactory.decodeResource( getResources() , R.raw.line ); surfaceView2 = (SurfaceView)findViewById(R.id.surface_level ); surfaceHolder2 = surfaceView2.getHolder(); SurfaceHolder.Callback level_callback = new SurfaceHolder.Callback() { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { //需要 on_level_change(new float[3]); } public void surfaceCreated(SurfaceHolder holder) { } public void surfaceDestroyed(SurfaceHolder holder) { } }; surfaceHolder2.addCallback( level_callback ); surfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); */ ////////////////////////////////////////////////////////////////////////////////////////// /* sensormanager = (SensorManager) getSystemService(SENSOR_SERVICE); sensors = sensormanager.getSensorList(Sensor.TYPE_ORIENTATION); SensorEventListener sl =new SensorEventListener () { public void onAccuracyChanged(Sensor sensor, int accuracy) { //不需要 } public void onSensorChanged(SensorEvent event) { on_level_change(event.values); } }; sensormanager.registerListener ( sl , sensors.get(0) , SensorManager.SENSOR_DELAY_GAME ); */ ///////////////////////////////////////////////////////////////////// Button run_script = (Button) this.findViewById(R.id.run_script); run_script.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { if (is_video == true) { print_screen(res.getString(R.string.video_rec_ing)); return; } if (is_audio == true) { print_screen(res.getString(R.string.audio_rec_ing)); return; } if (lua_file == "") { print_screen(res.getString(R.string.file_load_no)); return; } File f = new File("/sdcard/ez_Lua_Script_Camera/lua_scripts/" + lua_file); if (f.exists() == false) { print_screen(res.getString(R.string.file_load_fail)); return; } ((TextView) findViewById(R.id.lua_file_screen)).setText(lua_file); all_pics = 0; ((TextView) findViewById(R.id.shutter_times_screen)).setText("拍攝張數 : 00000"); (new lua_run()).start(); } }); Button about = (Button) this.findViewById(R.id.about); about.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { if (is_video == true) { print_screen(res.getString(R.string.video_rec_ing)); return; } if (is_audio == true) { print_screen(res.getString(R.string.audio_rec_ing)); return; } if (is_script_running == true) { print_screen(res.getString(R.string.script_running)); return; } Intent i = new Intent( Intent.ACTION_VIEW, Uri.parse("http://dl.dropbox.com/u/61164954/homepage/ez_LSC/index.htm")); startActivity(i); } }); Button audio_c = (Button) this.findViewById(R.id.audio); audio_c.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { if (is_script_running == true) { print_screen(res.getString(R.string.script_running)); return; } if (is_video == true) { print_screen(res.getString(R.string.video_rec_ing)); return; } if (is_audio == false) { print_screen(res.getString(R.string.audio_rec_start)); CharSequence cs = res.getString(R.string.stop); Button keepa = (Button) findViewById(R.id.audio); keepa.setText(cs); is_audio = true; (new audio()).start(); } else { arecorder.stop(); is_audio = false; print_screen(res.getString(R.string.audio_rec_end)); CharSequence xcs = res.getString(R.string.audio_rec); Button keepax = (Button) findViewById(R.id.audio); keepax.setText(xcs); camera.startPreview(); } } }); Button movie = (Button) this.findViewById(R.id.movie); movie.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { if (is_script_running == true) { print_screen(res.getString(R.string.script_running)); return; } if (is_audio == true) { print_screen(res.getString(R.string.audio_rec_ing)); return; } if (is_video == false) { print_screen(res.getString(R.string.video_rec_start)); CharSequence cs = res.getString(R.string.stop); Button keepa = (Button) findViewById(R.id.movie); keepa.setText(cs); parameters.setFocusMode("continuous-video"); camera.setParameters(parameters); is_video = true; (new video()).start(); } else { recorder.stop(); is_video = false; print_screen(res.getString(R.string.video_rec_end)); CharSequence xcs = res.getString(R.string.video_rec); Button keepax = (Button) findViewById(R.id.movie); keepax.setText(xcs); camera.lock(); camera.release(); camera = Camera.open(); parameters = camera.getParameters(); parameters.setPreviewSize(640, 480); parameters.setPreviewFrameRate(30); parameters.setJpegQuality(100); parameters.setFocusMode("continuous-video"); parameters.setPictureSize(2048, 1536); camera.setParameters(parameters); try { camera.setPreviewDisplay(surfaceHolder); } catch (IOException e) { } camera.startPreview(); } } }); Button lua = (Button) this.findViewById(R.id.lua); lua.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { if (is_script_running == true) { print_screen(res.getString(R.string.script_running)); return; } if (is_audio == true) { print_screen(res.getString(R.string.audio_rec_ing)); return; } if (is_video == true) { print_screen(res.getString(R.string.video_rec_ing)); return; } show_choose_Dialog(); } }); test_caller(); load_config(); try { player.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/shuttersound.ogg"); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { shutter_trigger.setDataSource("/sdcard/ez_Lua_Script_Camera/sound/trigger.wav"); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testInvalidConfig() { try { MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(12345) .list() .pretrain(false) .backprop(true) .build(); MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init(); fail("No exception thrown for invalid configuration"); } catch (IllegalStateException e) { // OK e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); fail("Unexpected exception thrown for invalid config"); } try { MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(12345) .list() .layer(1, new DenseLayer.Builder().nIn(3).nOut(4).build()) .layer(2, new OutputLayer.Builder().nIn(4).nOut(5).build()) .pretrain(false) .backprop(true) .build(); MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init(); fail("No exception thrown for invalid configuration"); } catch (IllegalStateException e) { // OK e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); fail("Unexpected exception thrown for invalid config"); } try { MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .seed(12345) .list() .layer(0, new DenseLayer.Builder().nIn(3).nOut(4).build()) .layer(2, new OutputLayer.Builder().nIn(4).nOut(5).build()) .pretrain(false) .backprop(true) .build(); MultiLayerNetwork net = new MultiLayerNetwork(conf); net.init(); fail("No exception thrown for invalid configuration"); } catch (IllegalStateException e) { // OK e.printStackTrace(); } catch (Throwable e) { e.printStackTrace(); fail("Unexpected exception thrown for invalid config"); } }