public void makeJSONObject() { try { events.put("name", this.eventName); events.put("type", "audio"); attributes.put("filename", this.audioFile); File desFilePath = new File(sourcePath); attributes.put("fileSize", desFilePath.length()); attributes.put("collectItem", collectItem); events.put("attributes", attributes); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public boolean JSONActions() { try { actions.put("audio-finished-playing", action); events.put("actions", actions); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } FileChannel src = null, des = null; try { File file = new File(destinationPath + "/audios"); File desFilePath = new File(sourcePath); String desPath = desFilePath.getName(); File desFile = new File(destinationPath + "/audios/" + desPath); if (!desFile.exists()) { if (file.isDirectory()) { src = new FileInputStream(sourcePath).getChannel(); des = new FileOutputStream(destinationPath + "/audios/" + desPath).getChannel(); } else { file.mkdir(); src = new FileInputStream(sourcePath).getChannel(); des = new FileOutputStream(destinationPath + "/audios/" + desPath).getChannel(); } } try { if (des != null) des.transferFrom(src, 0, src.size()); } catch (IOException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e); e.printStackTrace(); return false; } } catch (FileNotFoundException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e); e.printStackTrace(); return false; } finally { try { if (src != null) { src.close(); des.close(); } } catch (IOException e) { // TODO Auto-generated catch block JOptionPane.showMessageDialog(null, e); e.printStackTrace(); return false; } } return true; }