@Before public void setUp() throws Exception { // Generate junk to text regexp speed final int junkSize = 50000; final byte[] junk = new byte[junkSize]; for (int i = 0; i < junkSize; i++) { // We do not care about precision nor security, that junk for tests //noinspection NumericCastThatLosesPrecision,UnsecureRandomNumberGeneration junk[i] = (byte)(Math.random() * 10); } final String longString = StringUtil.repeat("1", junkSize); myStringJunk = String.format("%s:%s", longString, longString); myBase64Junk = Base64.encode(junk); myStringJunkWithSpaces = StringUtil.repeat("dd ddddddddd", junkSize); myStringJunkWithSpacesAndLine = myStringJunkWithSpaces + " c:/file:12"; }
@Override public void build(CompileContext context) throws ProjectBuildException { BuildDataPaths dataPaths = context.getProjectDescriptor().dataManager.getDataPaths(); MavenProjectConfiguration projectConfiguration = JpsMavenExtensionService.getInstance().getMavenProjectConfiguration(dataPaths); if (projectConfiguration == null) return; final MavenModuleResourceConfiguration moduleResourceConfiguration = projectConfiguration.moduleConfigurations.get(getModuleName(myArtifact.getName())); if (moduleResourceConfiguration != null && StringUtil.isNotEmpty(moduleResourceConfiguration.manifest)) { try { File output = new File(myArtifact.getOutputPath(), JarFile.MANIFEST_NAME); FileUtil.writeToFile(output, Base64.decode(moduleResourceConfiguration.manifest)); handleSkinnyWars(context, projectConfiguration, moduleResourceConfiguration); } // do not fail the whole 'Make' if there is an invalid manifest cached (e.g. non encoded string generated by previous IDEA version) catch (Exception e) { LOG.debug(e); } } }
/** * Extracts byte array from given data:URL string. * data:URL will be decoded from base64 if it contains the marker of base64 encoding. * * @param dataUrl data:URL-like string (may be quoted) * @return extracted byte array or {@code null} if it cannot be extracted. */ @Nullable public static byte[] getBytesFromDataUri(@Nonnull String dataUrl) { Matcher matcher = DATA_URI_PATTERN.matcher(StringUtil.unquoteString(dataUrl)); if (matcher.matches()) { try { String content = matcher.group(4); return ";base64".equalsIgnoreCase(matcher.group(3)) ? Base64.decode(content) : content.getBytes(CharsetToolkit.UTF8_CHARSET); } catch (IllegalArgumentException e) { return null; } } return null; }
private static byte[] readKeyMaterial(String endMarker, List<String> strings) throws IOException { StringBuilder buf = new StringBuilder(); for (String line : strings) { if (line.contains(endMarker)) { return Base64.decode(buf.toString()); } buf.append(line.trim()); } throw new IOException("Invalid PEM file: No end marker"); }
@Override public <T extends RemoteAgent> T createAgent(RemoteAgentProxyFactory agentProxyFactory, List<File> instanceLibraries, List<Class<?>> commonJarClasses, String specificsRuntimeModuleName, String specificsBuildJarPath, Class<T> agentInterface, String agentClassName, Class<?> pluginClass) throws Exception { List<Class<?>> allCommonJarClasses = new ArrayList<Class<?>>(); allCommonJarClasses.addAll(commonJarClasses); allCommonJarClasses.add(RemoteAgent.class); allCommonJarClasses.add(Base64.class); allCommonJarClasses.add(agentInterface); List<File> libraries = new ArrayList<File>(); libraries.addAll(instanceLibraries); for (Class<?> clazz : allCommonJarClasses) { libraries.add(new File(PathUtil.getJarPathForClass(clazz))); } File plugin = new File(PathUtil.getJarPathForClass(pluginClass)); String allPluginsDir = plugin.getParent(); if (plugin.isDirectory()) { // runtime behavior File specificsModule = new File(allPluginsDir, specificsRuntimeModuleName); libraries.add(specificsModule); } else { // build behavior File specificsDir = new File(allPluginsDir, FileUtil.toSystemDependentName(specificsBuildJarPath)); libraries.add(specificsDir); } return agentProxyFactory.createProxy(libraries, agentInterface, agentClassName); }
public void uploadItem(final WorkspaceInfo workspaceInfo, final PendingChange change, Object projectOrComponent, String progressTitle) throws TfsException, IOException { TfsRequestManager.executeRequest(myServerUri, projectOrComponent, new TfsRequestManager.Request<Void>(progressTitle) { @Override public Void execute(Credentials credentials, URI serverUri, @Nullable ProgressIndicator pi) throws Exception { String uploadUrl = TfsUtil.appendPath(myServerUri, myBeans.getUploadUrl(credentials, pi)); File file = VersionControlPath.getFile(change.getLocal()); long fileLength = file.length(); ArrayList<Part> parts = new ArrayList<Part>(); parts.add(new StringPart(SERVER_ITEM_FIELD, change.getItem(), "UTF-8")); parts.add(new StringPart(WORKSPACE_NAME_FIELD, workspaceInfo.getName())); parts.add(new StringPart(WORKSPACE_OWNER_FIELD, workspaceInfo.getOwnerName())); parts.add(new StringPart(LENGTH_FIELD, Long.toString(fileLength))); final byte[] hash = TfsFileUtil.calculateMD5(file); parts.add(new StringPart(HASH_FIELD, Base64.encode(hash))); // TODO: handle files too large to fit in a single POST parts.add(new StringPart(RANGE_FIELD, String.format("bytes=0-%d/%d", fileLength - 1, fileLength))); FilePart filePart = new FilePart(CONTENT_FIELD, SERVER_ITEM_FIELD, file); parts.add(filePart); filePart.setCharSet(null); WebServiceHelper .httpPost(uploadUrl, parts.toArray(new Part[parts.size()]), null, credentials, serverUri, myBeans.getUploadDownloadClient(false)); return null; } }); }
@Override public byte[] getByteArray(String key, byte[] def) { final String value = this.get(key,null); try{ return Base64.decode(value); }catch(Exception ex){ return def; } }
private static String decode(String value) { return new String(Base64.decode(value)); }
private static String encode(String password) { return new String(Base64.encode(password.getBytes(CharsetToolkit.UTF8_CHARSET))); }
public String getPlainItnPassword() { return new String(Base64.decode(getInstance().ITN_PASSWORD_CRYPT), CharsetToolkit.UTF8_CHARSET); }
public void setPlainItnPassword(String password) { ITN_PASSWORD_CRYPT = Base64.encode(password.getBytes(CharsetToolkit.UTF8_CHARSET)); }
@Transient @NotNull public String getPlainKeystorePassword() { return new String(Base64.decode(myKeyStorePassword)); }
@Transient public void setPlainKeystorePassword(@NotNull String password) { myKeyStorePassword = Base64.encode(password.getBytes(CharsetToolkit.UTF8_CHARSET)); }
@Transient @NotNull public String getPlainKeyPassword() { return new String(Base64.decode(myKeyPassword), CharsetToolkit.UTF8_CHARSET); }
@Transient public void setPlainKeyPassword(@NotNull String password) { myKeyPassword = Base64.encode(password.getBytes(CharsetToolkit.UTF8_CHARSET)); }
@Override public void putByteArray(String key, byte[] value) { this.put(key, Base64.encode(value)); }