List of usage examples for java.io RandomAccessFile writeBytes
@SuppressWarnings("deprecation") public final void writeBytes(String s) throws IOException
From source file:tvbrowser.ui.mainframe.MainFrame.java
@Override public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(dtde.getDropAction()); File[] files = getDragDropPlugins(dtde.getCurrentDataFlavors(), dtde.getTransferable()); try {/* w ww . j av a2 s . c o m*/ File tmpFile = File.createTempFile("plugins", ".txt"); StringBuilder alreadyInstalled = new StringBuilder(); StringBuilder notCompatiblePlugins = new StringBuilder(); for (File jarFile : files) { ClassLoader classLoader = null; try { URL[] urls = new URL[] { jarFile.toURI().toURL() }; classLoader = URLClassLoader.newInstance(urls, ClassLoader.getSystemClassLoader()); } catch (MalformedURLException exc) { } if (classLoader != null) { // Get the plugin name String pluginName = jarFile.getName(); pluginName = pluginName.substring(0, pluginName.length() - 4); try { String pluginId = "java." + pluginName.toLowerCase() + "." + pluginName; PluginProxy installedPlugin = PluginProxyManager.getInstance().getPluginForId(pluginId); TvDataServiceProxy service = TvDataServiceProxyManager.getInstance() .findDataServiceById(pluginName.toLowerCase() + '.' + pluginName); Class<?> pluginClass = classLoader.loadClass(pluginName.toLowerCase() + '.' + pluginName); Method getVersion = pluginClass.getMethod("getVersion", new Class[0]); Version version1 = null; try { version1 = (Version) getVersion.invoke(pluginClass, new Object[0]); } catch (Throwable t1) { t1.printStackTrace(); } if (installedPlugin != null && (installedPlugin.getInfo().getVersion().compareTo(version1) > 0 || (installedPlugin.getInfo().getVersion().compareTo(version1) == 0 && version1.isStable()))) { alreadyInstalled.append(installedPlugin.getInfo().getName()).append('\n'); } else if (service != null && (service.getInfo().getVersion().compareTo(version1) > 0 || (service.getInfo().getVersion().compareTo(version1) == 0 && version1.isStable()))) { alreadyInstalled.append(service.getInfo().getName()).append('\n'); } else { RandomAccessFile write = new RandomAccessFile(tmpFile, "rw"); String versionString = Integer.toString(version1.getMajor()) + '.' + (version1.getMinor() / 10) + (version1.getMinor() % 10) + '.' + version1.getSubMinor(); write.seek(write.length()); write.writeBytes("[plugin:" + pluginName + "]\n"); write.writeBytes("name_en=" + pluginName + "\n"); write.writeBytes("filename=" + jarFile.getName() + "\n"); write.writeBytes("version=" + versionString + "\n"); write.writeBytes("stable=" + version1.isStable() + "\n"); write.writeBytes("download=" + jarFile.toURI().toURL() + "\n"); write.writeBytes("category=unknown\n"); write.close(); } } catch (Exception e) { notCompatiblePlugins.append(jarFile.getName()).append("\n"); } } } if (alreadyInstalled.length() > 0) { showInfoTextMessage( mLocalizer.msg("update.alreadyInstalled", "The following Plugin in current version are already installed:"), alreadyInstalled.toString(), 400); } if (notCompatiblePlugins.length() > 0) { showInfoTextMessage( mLocalizer.msg("update.noTVBPlugin", "This following files are not TV-Browser Plugins:"), notCompatiblePlugins.toString(), 400); } if (tmpFile.length() > 0) { java.net.URL url = tmpFile.toURI().toURL(); SoftwareUpdater softwareUpdater = new SoftwareUpdater(url, false, true); mSoftwareUpdateItems = softwareUpdater.getAvailableSoftwareUpdateItems(); dtde.dropComplete(true); SoftwareUpdateDlg updateDlg = new SoftwareUpdateDlg(this, false, mSoftwareUpdateItems); updateDlg.setVisible(true); } else { dtde.rejectDrop(); dtde.dropComplete(false); } if (!tmpFile.delete()) { tmpFile.deleteOnExit(); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }