semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        int i;
        String dicomURL = request.getParameter("datasetURL");
        String contentType = request.getParameter("contentType");
        String studyUID = request.getParameter("studyUID");
        String seriesUID = request.getParameter("seriesUID");
        String objectUID = request.getParameter("objectUID");
        dicomURL += "&contentType=" + contentType + "&studyUID=" + studyUID + "&seriesUID=" + seriesUID + "&objectUID=" + objectUID + "&transferSyntax=1.2.840.10008.1.2.1";
        dicomURL = dicomURL.replace("+", "%2B");
        InputStream is = null;
        DataInputStream dis = null;
        try {
            URL url = new URL(dicomURL);
            is = url.openStream();
            dis = new DataInputStream(is);
            for (i = 0; i < dicomData.length; i++) dicomData[i] = dis.readUnsignedByte();
            String windowCenter = getElementValue("00281050");
            String windowWidth = getElementValue("00281051");
            request.getSession(true).setAttribute(WINDOW_CENTER_PARAM, windowCenter == null ? null : windowCenter.trim());
            request.getSession(true).setAttribute(WINDOW_WIDTH_PARAM, windowWidth == null ? null : windowWidth.trim());
            dis.skipBytes(50000000);
            is.close();
            dis.close();
            out.println("Success");
            out.close();
        } catch (Exception e) {
            log.error("Unable to read and send the DICOM dataset page", e);
        }
    }
protected static Parser buildParser(URL url) throws IOException, ParserException {
        Parser parser;
        URLConnection connection = openConnection(url);
        if (!(connection instanceof HttpURLConnection) || ((HttpURLConnection) connection).getResponseCode() == 200) {
            parser = new Parser(connection);
        } else {
            parser = null;
        }
        return parser;
    }
private String load(URL url) {
        BufferedReader r = null;
        try {
            r = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buf = new StringBuffer();
            while (r.ready()) {
                buf.append(r.readLine()).append('\n');
            }
            r.close();
            return buf.toString();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
public InputStream getDaoConfig(String connectionType) throws IOException {
        URL url = null;
        if (connectionType.equals(SQL.ORACLE)) {
            url = com.apelon.dts.db.admin.config.MigrateConfig.class.getResource("oracle.xml");
        } else if (connectionType.equals(SQL.SQL2K)) {
            url = com.apelon.dts.db.admin.config.MigrateConfig.class.getResource("sql2k.xml");
        }
        return url.openStream();
    }
public static void test2() throws Exception {
        int keySize = 1024;
        int dBlockSize = keySize / 8;
        int eBlockSize = dBlockSize - 8 - 3;
        CertAndKeyGen certAndKeyGen = new CertAndKeyGen("RSA", "MD5WithRSA");
        certAndKeyGen.generate(keySize);
        PublicKey publicKey = certAndKeyGen.getPublicKey();
        PrivateKey privateKey = certAndKeyGen.getPrivateKey();
        Cipher cipher1 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
        cipher1.init(Cipher.ENCRYPT_MODE, publicKey);
        String fileA = "C:/temp/a.txt";
        String fileB = "C:/temp/b.txt";
        String fileC = "C:/temp/c.txt";
        FileInputStream fis = new FileInputStream(fileA);
        FileOutputStream fos = new FileOutputStream(fileB, false);
        CipherOutputStream eos = new CipherOutputStream(fos, cipher1, eBlockSize);
        byte[] b = new byte[128];
        int i = fis.read(b);
        while (i != -1) {
            eos.write(b, 0, i);
            i = fis.read(b);
        }
        eos.flush();
        eos.close();
        fos.close();
        Cipher cipher2 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
        cipher2.init(Cipher.DECRYPT_MODE, privateKey);
        fis = new FileInputStream(fileB);
        CipherInputStream cis = new CipherInputStream(fis, cipher2, dBlockSize);
        FileOutputStream decodedFile = new FileOutputStream(fileC, false);
        int read = -1;
        while ((read = cis.read()) > -1) {
            decodedFile.write(read);
        }
        decodedFile.close();
        fis.close();
    }
public static void copyFile(String inName, String otName) throws Exception {
        File inFile = null;
        File otFile = null;
        try {
            inFile = new File(inName);
            otFile = new File(otName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (inFile == null || otFile == null) return;
        FileChannel sourceChannel = new FileInputStream(inFile).getChannel();
        FileChannel destinationChannel = new FileOutputStream(otFile).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
public void get(File fileToGet) throws IOException {
        String fileName = fileToGet.getName();
        URL url = new URL(this.endpointURL + fileName);
        URLConnection connection = url.openConnection();
        InputStream input = connection.getInputStream();
        log.debug("get: " + fileName);
        try {
            FileOutputStream fileStream = new FileOutputStream(fileToGet);
            byte[] bt = new byte[10000];
            int cnt = input.read(bt);
            log.debug("Read bytes: " + cnt);
            while (cnt != -1) {
                fileStream.write(bt, 0, cnt);
                cnt = input.read(bt);
            }
            input.close();
            fileStream.close();
        } catch (IOException e) {
            new File(fileName).delete();
            throw e;
        }
    }
public void delete(String fileName) throws IOException {
        log.debug("deleting: " + fileName);
        URL url = new URL(this.endpointURL + "?operation=delete&filename=" + fileName);
        URLConnection connection = url.openConnection();
        connection.setDoOutput(false);
        connection.setDoInput(true);
        connection.setUseCaches(false);
        connection.getInputStream();
    }
public static synchronized BufferedImage loadBufferedJPEGImage(URL url) {
        BufferedImage image = null;
        if (url != null) {
            InputStream in = null;
            try {
                in = url.openStream();
                JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
                image = decoder.decodeAsBufferedImage();
            } catch (Exception e) {
                log.severe("URL: " + url + " - " + e.getMessage());
                image = null;
            } finally {
                try {
                    if (in != null) in.close();
                } catch (IOException ioe) {
                    log.severe("URL: " + url + " - " + ioe.getMessage());
                }
            }
            if (image != null) {
                log.config("Image type : " + image.getType());
                if (image.getWidth() <= 0 || image.getHeight() <= 0) {
                    log.severe("URL: " + url + " =0");
                    image = null;
                }
            }
        }
        return image;
    }
private void output(HttpServletResponse resp, InputStream is, long length, String fileName) throws Exception {
        resp.reset();
        String mimeType = "image/jpeg";
        resp.setContentType(mimeType);
        resp.setContentLength((int) length);
        resp.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");
        resp.setHeader("Cache-Control", "must-revalidate");
        ServletOutputStream sout = resp.getOutputStream();
        IOUtils.copy(is, sout);
        sout.flush();
        resp.flushBuffer();
    }
public void writeConfigurationFile() throws IOException, ComponentException {
        SystemConfig config = parent.getParentSystem().getConfiguration();
        File original = config.getLocation();
        File backup = new File(original.getParentFile(), original.getName() + "." + System.currentTimeMillis());
        FileInputStream in = new FileInputStream(original);
        FileOutputStream out = new FileOutputStream(backup);
        byte[] buffer = new byte[2048];
        try {
            int bytesread = 0;
            while ((bytesread = in.read(buffer)) > 0) {
                out.write(buffer, 0, bytesread);
            }
        } catch (IOException e) {
            logger.warn("Failed to copy backup of configuration file");
            throw e;
        } finally {
            in.close();
            out.close();
        }
        FileWriter replace = new FileWriter(original);
        replace.write(config.toFileFormat());
        replace.close();
        logger.info("Re-wrote configuration file " + original.getPath());
    }
protected String parseAction() throws ChangesOnServerException, ConnectionException, RequestCancelledException {
        GetPageRequest request = getHttpClient().createGetPageRequest();
        request.setUrl("http://www.zippyshare.com/index_old.jsp");
        HttpResponse response = executeRequest(request);
        try {
            Parser p = new Parser(response.getResponseBody());
            String action = p.parseOne("enctype=\"multipart/form-data\" action=\"(.*)\">");
            return action;
        } catch (ParsingException ex) {
            throw new ChangesOnServerException();
        } catch (IOException ex) {
            throw new ChangesOnServerException();
        }
    }
public static void copy(File source, File dest) throws IOException {
        if (dest.isDirectory()) {
            dest = new File(dest + File.separator + source.getName());
        }
        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();
            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
            out.write(buf);
        } finally {
            if (in != null) in.close();
            if (out != null) out.close();
        }
    }
private String generateCode(String seed) {
        try {
            Security.addProvider(new FNVProvider());
            MessageDigest digest = MessageDigest.getInstance("FNV-1a");
            digest.update((seed + UUID.randomUUID().toString()).getBytes());
            byte[] hash1 = digest.digest();
            String sHash1 = "m" + (new String(LibraryBase64.encode(hash1))).replaceAll("=", "").replaceAll("-", "_");
            return sHash1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
private void copy(String inputPath, String outputPath, String name) {
        try {
            FileReader in = new FileReader(inputPath + name);
            FileWriter out = new FileWriter(outputPath + name);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private void httpDo(HttpUriRequest hr, String url, Map<String, String> headers, AjaxStatus status) throws ClientProtocolException, IOException {
        if (AGENT != null) {
            hr.addHeader("User-Agent", AGENT);
        }
        if (headers != null) {
            for (String name : headers.keySet()) {
                hr.addHeader(name, headers.get(name));
            }
        }
        if (GZIP && headers == null || !headers.containsKey("Accept-Encoding")) {
            hr.addHeader("Accept-Encoding", "gzip");
        }
        String cookie = makeCookie();
        if (cookie != null) {
            hr.addHeader("Cookie", cookie);
        }
        if (ah != null) {
            ah.applyToken(this, hr);
        }
        DefaultHttpClient client = getClient();
        HttpContext context = new BasicHttpContext();
        CookieStore cookieStore = new BasicCookieStore();
        context.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
        HttpResponse response = client.execute(hr, context);
        byte[] data = null;
        String redirect = url;
        int code = response.getStatusLine().getStatusCode();
        String message = response.getStatusLine().getReasonPhrase();
        String error = null;
        if (code < 200 || code >= 300) {
            try {
                HttpEntity entity = response.getEntity();
                byte[] s = AQUtility.toBytes(entity.getContent());
                error = new String(s, "UTF-8");
                AQUtility.debug("error", error);
            } catch (Exception e) {
                AQUtility.debug(e);
            }
        } else {
            HttpEntity entity = response.getEntity();
            HttpHost currentHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
            redirect = currentHost.toURI() + currentReq.getURI();
            int size = Math.max(32, Math.min(1024 * 64, (int) entity.getContentLength()));
            PredefinedBAOS baos = new PredefinedBAOS(size);
            Header encoding = entity.getContentEncoding();
            if (encoding != null && encoding.getValue().equalsIgnoreCase("gzip")) {
                InputStream is = new GZIPInputStream(entity.getContent());
                AQUtility.copy(is, baos);
            } else {
                entity.writeTo(baos);
            }
            data = baos.toByteArray();
        }
        AQUtility.debug("response", code);
        if (data != null) {
            AQUtility.debug(data.length, url);
        }
        status.code(code).message(message).error(error).redirect(redirect).time(new Date()).data(data).client(client).context(context).headers(response.getAllHeaders());
    }
public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException {
        InputStream urlStream = null;
        BufferedInputStream bis = null;
        AudioFileFormat fileFormat = null;
        urlStream = url.openStream();
        AudioInputStream result = null;
        try {
            bis = new BufferedInputStream(urlStream, bisBufferSize);
            result = getAudioInputStream((InputStream) bis);
        } finally {
            if (result == null) {
                urlStream.close();
            }
        }
        return result;
    }
public Resultado procesar() {
        if (resultado != null) return resultado;
        int[] a = new int[elems.size()];
        Iterator iter = elems.iterator();
        int w = 0;
        while (iter.hasNext()) {
            a[w] = ((Integer) iter.next()).intValue();
            w++;
        }
        int n = a.length;
        long startTime = System.currentTimeMillis();
        int i, j, temp;
        for (i = 0; i < n - 1; i++) {
            for (j = i; j < n - 1; j++) {
                if (a[i] > a[j + 1]) {
                    temp = a[i];
                    a[i] = a[j + 1];
                    a[j + 1] = temp;
                    pasos++;
                }
            }
        }
        long endTime = System.currentTimeMillis();
        resultado = new Resultado((int) (endTime - startTime), pasos, a.length);
        System.out.println("Resultado BB: " + resultado);
        return resultado;
    }
private String generate(String value) throws Exception {
        String resStr = null;
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(value.getBytes("utf-8"), 0, value.length());
            byte[] result = md.digest();
            resStr = FTGenerate.convertToHex(result);
            md.reset();
        } catch (NoSuchAlgorithmException nae) {
            this.getLog().severe("Hash no funcionando");
            nae.printStackTrace();
            throw new Exception("Hash no funcionando");
        } catch (UnsupportedEncodingException ee) {
            this.getLog().severe("Encoding no funcionando");
            ee.printStackTrace();
            throw new Exception("Encoding no funcionando");
        }
        return resStr;
    }
private void callbackWS(String xmlControl, String ws_results, long docId) {
        SimpleProvider config;
        Service service;
        Object ret;
        Call call;
        Object[] parameter;
        String method;
        String wsurl;
        URL url;
        NodeList delegateNodes;
        Node actualNode;
        InputSource xmlcontrolstream;
        try {
            xmlcontrolstream = new InputSource(new StringReader(xmlControl));
            delegateNodes = SimpleXMLParser.parseDocument(xmlcontrolstream, AgentBehaviour.XML_CALLBACK);
            actualNode = delegateNodes.item(0);
            wsurl = SimpleXMLParser.findChildEntry(actualNode, AgentBehaviour.XML_URL);
            method = SimpleXMLParser.findChildEntry(actualNode, AgentBehaviour.XML_METHOD);
            if (wsurl == null || method == null) {
                System.out.println("----- Did not get method or wsurl from the properties! -----");
                return;
            }
            url = new java.net.URL(wsurl);
            try {
                url.openConnection().connect();
            } catch (IOException ex) {
                System.out.println("----- Could not connect to the webservice! -----");
            }
            Vector v_param = new Vector();
            v_param.add(ws_results);
            v_param.add(new Long(docId));
            parameter = v_param.toArray();
            config = new SimpleProvider();
            config.deployTransport("http", new HTTPSender());
            service = new Service(config);
            call = (Call) service.createCall();
            call.setTargetEndpointAddress(url);
            call.setOperationName(new QName("http://schemas.xmlsoap.org/soap/encoding/", method));
            try {
                ret = call.invoke(parameter);
                if (ret == null) {
                    ret = new String("No response from callback function!");
                }
                System.out.println("Callback function returned: " + ret);
            } catch (RemoteException ex) {
                System.out.println("----- Could not invoke the method! -----");
            }
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }
    }
public void setUp() throws Exception {
        logger.finer("******************** set up ********************");
        Properties props;
        if (XMLDBTestSuite.propertiesFileName == null) {
            String defaultPropsFileLocation = "test/xmldb/XMLDBTestSuite.properties";
            URL url = this.getClass().getClassLoader().getResource(defaultPropsFileLocation);
            if (url == null) {
                throw new Exception("failed to find default props file at " + defaultPropsFileLocation);
            }
            props = loadProps(url.openConnection().getInputStream());
        } else {
            props = loadProps(XMLDBTestSuite.propertiesFileName);
        }
        String driver = props.getProperty("driverName");
        String collectionURI = props.getProperty("URI");
        Database database = (Database) Class.forName(driver).newInstance();
        collectionStorageHelper = new CollectionStorageHelper(collectionURI);
        rootCollectionName = collectionStorageHelper.getCollectionName();
        Collection root = database.getCollection(collectionURI, null, null);
        CollectionManagementService service = (CollectionManagementService) root.getService(CollectionManagementService.SERVICE_NAME, "1.0");
        String childCollection = "child";
        removeChildCollection(root, childCollection, service);
        col = service.createCollection(childCollection);
        assertNotNull("XMLDBTestCase.setUp() - Collection could not be created", col);
        logger.info("created child collection '" + col.getName() + "' parent is '" + col.getParentCollection().getName() + "'");
        assertEquals("Root collection name should match childs parent name", rootCollectionName, col.getParentCollection().getName());
        document = createXMLFile(xmlFileName);
        assertNotNull("XMLDBTestCase.setUp() - failed to create XML file", document);
    }
@Override
    public void trainClassifier(File dir, String... args) throws Exception {
        String[] command = new String[args.length + 3];
        command[0] = this.getCommand();
        System.arraycopy(args, 0, command, 1, args.length);
        command[command.length - 2] = new File(dir, "training-data.libsvm").getPath();
        command[command.length - 1] = new File(dir, this.getModelName()).getPath();
        Process process = Runtime.getRuntime().exec(command);
        IOUtils.copy(process.getInputStream(), System.out);
        IOUtils.copy(process.getErrorStream(), System.err);
        process.waitFor();
    }
public void copy(File source, File destination) {
        try {
            FileInputStream fileInputStream = new FileInputStream(source);
            FileOutputStream fileOutputStream = new FileOutputStream(destination);
            FileChannel inputChannel = fileInputStream.getChannel();
            FileChannel outputChannel = fileOutputStream.getChannel();
            transfer(inputChannel, outputChannel, source.length(), 1024 * 1024 * 32, true, true);
            fileInputStream.close();
            fileOutputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private static void copyFile(File in, File out) throws Exception {
        final FileInputStream input = new FileInputStream(in);
        try {
            final FileOutputStream output = new FileOutputStream(out);
            try {
                final byte[] buf = new byte[4096];
                int readBytes = 0;
                while ((readBytes = input.read(buf)) != -1) {
                    output.write(buf, 0, readBytes);
                }
            } finally {
                output.close();
            }
        } finally {
            input.close();
        }
    }
private static Image tryLoadImageFromFile(String filename, String path, int width, int height) {
        Image image = null;
        try {
            URL url;
            url = new URL("file:" + path + pathSeparator + fixFilename(filename));
            if (url.openStream() != null) {
                image = Toolkit.getDefaultToolkit().getImage(url);
            }
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        if (image != null) {
            return image.getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH);
        } else {
            return null;
        }
    }
private static ImageIcon tryLoadImageIconFromResource(String filename, String path, int width, int height) {
        ImageIcon icon = null;
        try {
            URL url = cl.getResource(path + pathSeparator + fixFilename(filename));
            if (url != null && url.openStream() != null) {
                icon = new ImageIcon(url);
            }
        } catch (Exception e) {
        }
        if (icon == null) {
            return null;
        }
        if ((icon.getIconWidth() == width) && (icon.getIconHeight() == height)) {
            return icon;
        } else {
            return new ImageIcon(icon.getImage().getScaledInstance(width, height, java.awt.Image.SCALE_SMOOTH));
        }
    }