List of usage examples for java.util.zip InflaterInputStream InflaterInputStream
public InflaterInputStream(InputStream in)
From source file:org.talend.designer.runprocess.java.JavaProcessor.java
@Override public void generateEsbFiles() throws ProcessorException { List<? extends INode> graphicalNodes = process.getGraphicalNodes(); // process.getGeneratingNodes(); try {//ww w .j ava2s . c o m IPath jobPackagePath = getSrcCodePath().removeLastSegments(1); IFolder jobPackageFolder = this.getCodeProject().getFolder(jobPackagePath); IFolder wsdlsPackageFolder = jobPackageFolder.getFolder("wsdl"); //$NON-NLS-1$ if (wsdlsPackageFolder.exists()) { wsdlsPackageFolder.delete(true, null); } for (INode node : graphicalNodes) { if ("tESBConsumer".equals(node.getComponent().getName()) && node.isActivate()) { //$NON-NLS-1$ // retrieve WSDL content (compressed-n-encoded) -> zip-content.-> wsdls.(first named main.wsdl) String wsdlContent = (String) node.getPropertyValue("WSDL_CONTENT"); //$NON-NLS-1$ String uniqueName = node.getUniqueName(); if (null != uniqueName && null != wsdlContent && !wsdlContent.trim().isEmpty()) { // configure decoding and uncompressing InputStream wsdlStream = new BufferedInputStream(new InflaterInputStream( new Base64InputStream(new ByteArrayInputStream(wsdlContent.getBytes())))); if (!wsdlsPackageFolder.exists()) { wsdlsPackageFolder.create(true, true, null); } // generate WSDL file if (checkIsZipStream(wsdlStream)) { ZipInputStream zipIn = new ZipInputStream(wsdlStream); ZipEntry zipEntry = null; while ((zipEntry = zipIn.getNextEntry()) != null) { String outputName = zipEntry.getName(); if ("main.wsdl".equals(outputName)) { //$NON-NLS-1$ outputName = uniqueName + ".wsdl"; //$NON-NLS-1$ } IFile wsdlFile = wsdlsPackageFolder.getFile(outputName); if (!wsdlFile.exists()) { // cause create file will do a close. add a warp to ignore close. InputStream unCloseIn = new FilterInputStream(zipIn) { @Override public void close() throws IOException { }; }; wsdlFile.create(unCloseIn, true, null); } zipIn.closeEntry(); } zipIn.close(); } else { IFile wsdlFile = wsdlsPackageFolder.getFile(uniqueName + ".wsdl"); //$NON-NLS-1$ wsdlFile.create(wsdlStream, true, null); } } } } } catch (CoreException e) { if (e.getStatus() != null && e.getStatus().getException() != null) { ExceptionHandler.process(e.getStatus().getException()); } throw new ProcessorException(Messages.getString("Processor.tempFailed"), e); //$NON-NLS-1$ } catch (IOException e) { throw new ProcessorException(Messages.getString("Processor.tempFailed"), e); //$NON-NLS-1$ } boolean samEnabled = false; boolean slEnabled = false; for (INode node : graphicalNodes) { if (node.isActivate()) { final String nodeName = node.getComponent().getName(); Object slValue = null, samValue = null; if ("tESBConsumer".equals(nodeName) //$NON-NLS-1$ || "tRESTClient".equals(nodeName) //$NON-NLS-1$ || "tRESTRequest".equals(nodeName) //$NON-NLS-1$ || "cCXFRS".equals(nodeName)) { //$NON-NLS-1$ if (!slEnabled) { slValue = node.getPropertyValue("SERVICE_LOCATOR"); //$NON-NLS-1$ } if (!samEnabled) { samValue = node.getPropertyValue("SERVICE_ACTIVITY_MONITOR"); //$NON-NLS-1$ } } else if ("cCXF".equals(nodeName)) { //$NON-NLS-1$ if (!slEnabled) { slValue = node.getPropertyValue("ENABLE_SL"); //$NON-NLS-1$ } if (!samEnabled) { samValue = node.getPropertyValue("ENABLE_SAM"); //$NON-NLS-1$ } } if (null != slValue) { slEnabled = (Boolean) slValue; } if (null != samValue) { samEnabled = (Boolean) samValue; } if (samEnabled && slEnabled) { break; } } } if (samEnabled || slEnabled) { File esbConfigsSourceFolder = EsbConfigUtils.getEclipseEsbFolder(); if (!esbConfigsSourceFolder.exists()) { RunProcessPlugin.getDefault().getLog() .log(new Status(IStatus.WARNING, RunProcessPlugin.getDefault().getBundle().getSymbolicName(), "ESB configuration folder does not exists - " + esbConfigsSourceFolder.toURI())); //$NON-NLS-1$ return; } ITalendProcessJavaProject tProcessJvaProject = this.getTalendJavaProject(); if (tProcessJvaProject == null) { return; } IFolder esbConfigsTargetFolder = tProcessJvaProject.getResourcesFolder(); // add SAM config file to classpath if (samEnabled) { copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "agent.properties"); //$NON-NLS-1$ } // add SL config file to classpath if (slEnabled) { copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "locator.properties"); //$NON-NLS-1$ } } }
From source file:com.ichi2.anki.SyncClient.java
public static void fullSyncFromServer(String password, String username, String deckName, String deckPath) { // Log.i(AnkiDroidApp.TAG, "password = " + password + ", user = " + username + ", d = " + deckName); try {//from w w w . j a va 2 s.c om String data = "p=" + URLEncoder.encode(password, "UTF-8") + "&u=" + URLEncoder.encode(username, "UTF-8") + "&d=" + URLEncoder.encode(deckName, "UTF-8"); // Log.i(AnkiDroidApp.TAG, "Data json = " + data); HttpPost httpPost = new HttpPost(AnkiDroidProxy.SYNC_URL + "fulldown"); StringEntity entity = new StringEntity(data); httpPost.setEntity(entity); httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpPost); Log.i(AnkiDroidApp.TAG, "Response = " + response.toString()); HttpEntity entityResponse = response.getEntity(); Log.i(AnkiDroidApp.TAG, "Entity's response = " + entityResponse.toString()); InputStream content = entityResponse.getContent(); Log.i(AnkiDroidApp.TAG, "Content = " + content.toString()); Utils.writeToFile(new InflaterInputStream(content), deckPath); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { Log.i(AnkiDroidApp.TAG, "ClientProtocolException = " + e.getMessage()); } catch (IOException e) { Log.i(AnkiDroidApp.TAG, "IOException = " + e.getMessage()); } }