semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public DocumentDialog(Frame frame, String title, String document) {
        setTitle(title);
        textArea = new JTextArea();
        textPane = new StdScrollPane(textArea, StdScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, StdScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        textArea.setEditable(false);
        getContentPane().add(textPane);
        URL url = DocumentDialog.class.getClassLoader().getResource(document);
        try {
            StringBuilder sb = new StringBuilder();
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            String buildNumber = MessageBundle.getBuildNumber();
            String releaseNumber = MessageBundle.getReleaseNumber();
            String tmp;
            while ((tmp = in.readLine()) != null) {
                tmp = tmp.replace("${build_number}", buildNumber);
                tmp = tmp.replace("${release_number}", releaseNumber);
                sb.append(tmp + "\n");
            }
            textArea.setText(sb.toString());
            textArea.setCaretPosition(0);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
private static void addFileToTarGz(TarArchiveOutputStream taro, String path, String base) throws IOException {
        File f = new File(path);
        String entryName = base + f.getName();
        FileInputStream goIn = new FileInputStream(f);
        TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
        taro.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        taro.putArchiveEntry(tarEntry);
        if (f.isFile()) {
            IOUtils.copy(goIn, taro);
            taro.closeArchiveEntry();
        } else {
            taro.closeArchiveEntry();
            File[] children = f.listFiles();
            if (children != null) {
                for (File child : children) {
                    addFileToTarGz(taro, child.getAbsolutePath(), entryName + "/");
                }
            }
        }
        taro.close();
        goIn.close();
    }
public String downloadFromUrl(URL url) {
        BufferedReader dis;
        String content = "";
        HttpURLConnection urlConn = null;
        try {
            urlConn = (HttpURLConnection) url.openConnection();
            urlConn.setDoInput(true);
            urlConn.setUseCaches(false);
            urlConn.setAllowUserInteraction(false);
            dis = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
            String line;
            while ((line = dis.readLine()) != null) {
                content = content.concat(line);
                content = content.concat("\n");
            }
        } catch (MalformedURLException ex) {
            System.err.println(ex + " (downloadFromUrl)");
        } catch (java.io.IOException iox) {
            System.out.println(iox + " (downloadFromUrl)");
        } catch (Exception generic) {
            System.out.println(generic.toString() + " (downloadFromUrl)");
        } finally {
        }
        return content;
    }
private void duplicateTable(Connection scon, Connection dcon, String table) {
        logger.debug("Duplicating table " + table);
        Statement creTab, stmt;
        ResultSet tuples, columns, keys;
        int c;
        String insert = "";
        PreparedStatement insTup;
        try {
            columns = scon.getMetaData().getColumns(null, null, table, null);
            keys = scon.getMetaData().getPrimaryKeys(null, null, table);
            creTab = dcon.createStatement();
            creTab.execute(getCreateTableCommand(columns, keys));
            stmt = scon.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            stmt.setFetchSize(50);
            tuples = stmt.executeQuery("SELECT * FROM " + table);
            c = tuples.getMetaData().getColumnCount();
            insert = "INSERT INTO " + table + " VALUES(";
            for (int j = 1; j <= c; j++) insert += "?,";
            insert = insert.substring(0, insert.length() - 1) + ")";
            logger.debug("Insert pattern " + insert);
            insTup = dcon.prepareStatement(insert);
            while (tuples.next()) {
                for (int j = 1; j <= c; j++) insTup.setObject(j, tuples.getObject(j));
                insTup.executeUpdate();
            }
            dcon.commit();
        } catch (Exception e) {
            logger.error("Unable to copy table " + table + ": " + e);
            try {
                dcon.rollback();
            } catch (SQLException e1) {
                logger.fatal(e1);
            }
        }
    }
private void duplicateIndices(Connection scon, Connection dcon, String table) {
        try {
            String idx_name, idx_att, query;
            ResultSet idxs = scon.getMetaData().getIndexInfo(null, null, table, false, false);
            Statement stmt = dcon.createStatement();
            while (idxs.next()) {
                idx_name = idxs.getString(6);
                idx_att = idxs.getString(9);
                idx_name += "_" + idx_att + "_idx";
                logger.debug("Creating index " + idx_name);
                query = "CREATE INDEX " + idx_name + " ON " + table + "(" + idx_att + ")";
                stmt.executeUpdate(query);
                dcon.commit();
            }
        } catch (Exception e) {
            logger.error("Unable to copy indices " + e);
            try {
                dcon.rollback();
            } catch (SQLException e1) {
                logger.fatal(e1);
            }
        }
    }
public void run() {
        try {
            status = UploadStatus.INITIALISING;
            if (megaUploadAccount.loginsuccessful) {
                login = true;
                host = megaUploadAccount.username + " | MegaUpload.com";
            } else {
                login = false;
                host = "MegaUpload.com";
            }
            initialize();
            HttpClient httpclient = new DefaultHttpClient();
            httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            filelength = file.length();
            generateMegaUploadID();
            if (login) {
                status = UploadStatus.GETTINGCOOKIE;
                usercookie = MegaUploadAccount.getUserCookie();
                postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&" + usercookie + "&s=" + filelength;
            } else {
                postURL = megauploadlink + "upload_done.php?UPLOAD_IDENTIFIER=" + uploadID + "&user=undefined&s=" + filelength;
            }
            HttpPost httppost = new HttpPost(postURL);
            httppost.setHeader("Cookie", usercookie);
            MultipartEntity mpEntity = new MultipartEntity();
            mpEntity.addPart("", new MonitoredFileBody(file, uploadProgress));
            httppost.setEntity(mpEntity);
            NULogger.getLogger().info("Now uploading your file into megaupload...........................");
            status = UploadStatus.UPLOADING;
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();
            NULogger.getLogger().info(response.getStatusLine().toString());
            if (resEntity != null) {
                status = UploadStatus.GETTINGLINK;
                downloadlink = EntityUtils.toString(resEntity);
                downloadlink = CommonUploaderTasks.parseResponse(downloadlink, "downloadurl = '", "'");
                downURL = downloadlink;
                NULogger.getLogger().log(Level.INFO, "Download Link : {0}", downURL);
                uploadFinished();
            }
        } catch (Exception ex) {
            Logger.getLogger(MegaUpload.class.getName()).log(Level.SEVERE, null, ex);
            uploadFailed();
        }
    }
public static boolean decodeFileToFile(final String infile, final String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.DECODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            final byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (final java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (final Exception exc) {
            }
            try {
                out.close();
            } catch (final Exception exc) {
            }
        }
        return success;
    }
public static boolean encodeFileToFile(final String infile, final String outfile) {
        boolean success = false;
        java.io.InputStream in = null;
        java.io.OutputStream out = null;
        try {
            in = new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(infile)), Base64.ENCODE);
            out = new java.io.BufferedOutputStream(new java.io.FileOutputStream(outfile));
            final byte[] buffer = new byte[65536];
            int read = -1;
            while ((read = in.read(buffer)) >= 0) {
                out.write(buffer, 0, read);
            }
            success = true;
        } catch (final java.io.IOException exc) {
            exc.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (final Exception exc) {
            }
            try {
                out.close();
            } catch (final Exception exc) {
            }
        }
        return success;
    }
protected void initializeFromURL(URL url) throws IOException {
        URLConnection connection = url.openConnection();
        String message = this.validateURLConnection(connection, DBASE_CONTENT_TYPES);
        if (message != null) {
            throw new IOException(message);
        }
        this.channel = Channels.newChannel(WWIO.getBufferedInputStream(connection.getInputStream()));
        this.initialize();
    }
private boolean Try(URL url, Metafile mf) throws Throwable {
        InputStream is = null;
        HttpURLConnection con = null;
        boolean success = false;
        try {
            con = (HttpURLConnection) url.openConnection();
            con.setRequestMethod("GET");
            con.connect();
            is = con.getInputStream();
            Response r = new Response(is);
            responses.add(r);
            peers.addAll(r.peers);
            Main.log.info("got " + r.peers.size() + " peers from " + url);
            success = true;
        } finally {
            if (is != null) is.close();
            if (con != null) con.disconnect();
        }
        return success;
    }
private InputStream openConnection(URL url) throws IOException, DODSException {
        connection = url.openConnection();
        if (acceptDeflate) connection.setRequestProperty("Accept-Encoding", "deflate");
        connection.connect();
        InputStream is = null;
        int retry = 1;
        long backoff = 100L;
        while (true) {
            try {
                is = connection.getInputStream();
                break;
            } catch (NullPointerException e) {
                System.out.println("DConnect NullPointer; retry open (" + retry + ") " + url);
                try {
                    Thread.currentThread().sleep(backoff);
                } catch (InterruptedException ie) {
                }
            } catch (FileNotFoundException e) {
                System.out.println("DConnect FileNotFound; retry open (" + retry + ") " + url);
                try {
                    Thread.currentThread().sleep(backoff);
                } catch (InterruptedException ie) {
                }
            }
            if (retry == 3) throw new DODSException("Connection cannot be opened");
            retry++;
            backoff *= 2;
        }
        String type = connection.getHeaderField("content-description");
        handleContentDesc(is, type);
        ver = new ServerVersion(connection.getHeaderField("xdods-server"));
        String encoding = connection.getContentEncoding();
        return handleContentEncoding(is, encoding);
    }
public DAS getDAS() throws MalformedURLException, IOException, ParseException, DASException, DODSException {
        InputStream is;
        if (fileStream != null) is = parseMime(fileStream); else {
            URL url = new URL(urlString + ".das" + projString + selString);
            if (dumpDAS) {
                System.out.println("--DConnect.getDAS to " + url);
                copy(url.openStream(), System.out);
                System.out.println("\n--DConnect.getDAS END1");
                dumpBytes(url.openStream(), 100);
                System.out.println("\n-DConnect.getDAS END2");
            }
            is = openConnection(url);
        }
        DAS das = new DAS();
        try {
            das.parse(is);
        } finally {
            is.close();
            if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect();
        }
        return das;
    }
public DDS getDDS() throws MalformedURLException, IOException, ParseException, DDSException, DODSException {
        InputStream is;
        if (fileStream != null) is = parseMime(fileStream); else {
            URL url = new URL(urlString + ".dds" + projString + selString);
            is = openConnection(url);
        }
        DDS dds = new DDS();
        try {
            dds.parse(is);
        } finally {
            is.close();
            if (connection instanceof HttpURLConnection) ((HttpURLConnection) connection).disconnect();
        }
        return dds;
    }
@Override
    protected void copy(Reader reader, OutputStream outputs) throws IOException {
        if (outputs == null) {
            throw new NullPointerException();
        }
        if (reader == null) {
            throw new NullPointerException();
        }
        ZipOutputStream zipoutputs = null;
        try {
            zipoutputs = new ZipOutputStream(outputs);
            zipoutputs.putNextEntry(new ZipEntry("default"));
            IOUtils.copy(reader, zipoutputs);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        } finally {
            if (zipoutputs != null) {
                zipoutputs.close();
            }
            if (reader != null) {
                reader.close();
            }
        }
    }
@Override
    protected void copy(InputStream inputs, OutputStream outputs) throws IOException {
        if (outputs == null) {
            throw new NullPointerException();
        }
        if (inputs == null) {
            throw new NullPointerException();
        }
        ZipOutputStream zipoutputs = null;
        try {
            zipoutputs = new ZipOutputStream(outputs);
            zipoutputs.putNextEntry(new ZipEntry("default"));
            IOUtils.copy(inputs, zipoutputs);
        } catch (IOException e) {
            e.printStackTrace();
            throw e;
        } finally {
            if (zipoutputs != null) {
                zipoutputs.close();
            }
            if (inputs != null) {
                inputs.close();
            }
        }
    }
@Override
    public void run() {
        try {
            File dest = new File(location);
            if ((dest.getParent() != null && !dest.getParentFile().isDirectory() && !dest.getParentFile().mkdirs())) {
                throw new IOException("Impossible de créer un dossier (" + dest.getParent() + ").");
            } else if (dest.exists() && !dest.delete()) {
                throw new IOException("Impossible de supprimer un ancien fichier (" + dest + ").");
            } else if (!dest.createNewFile()) {
                throw new IOException("Impossible de créer un fichier (" + dest + ").");
            }
            FileChannel in = new FileInputStream(file).getChannel();
            FileChannel out = new FileOutputStream(dest).getChannel();
            try {
                in.transferTo(0, in.size(), out);
            } finally {
                in.close();
                out.close();
            }
        } catch (Exception e) {
            Main.fenetre().erreur(Fenetre.ERREUR_FATALE_UPDATE, e);
        } finally {
            file.delete();
        }
    }
public static void compress(final File zip, final Map<InputStream, String> entries, final IProgressMonitor monitor) throws IOException {
        if (zip == null || entries == null || CollectionUtils.isEmpty(entries.keySet())) throw new IllegalArgumentException("One ore more parameters are empty!");
        if (zip.exists()) zip.delete(); else if (!zip.getParentFile().exists()) zip.getParentFile().mkdirs();
        ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zip)));
        out.setLevel(Deflater.BEST_COMPRESSION);
        try {
            for (InputStream inputStream : entries.keySet()) {
                ZipEntry zipEntry = new ZipEntry(skipBeginningSlash(entries.get(inputStream)));
                out.putNextEntry(zipEntry);
                IOUtils.copy(inputStream, out);
                out.closeEntry();
                inputStream.close();
                if (monitor != null) monitor.worked(1);
            }
        } finally {
            IOUtils.closeQuietly(out);
        }
    }
public static void extract(final File destDir, final ZipInfo zipInfo, final IProgressMonitor monitor) throws IOException {
        if (!destDir.exists()) destDir.mkdirs();
        for (String key : zipInfo.getEntryKeys()) {
            ZipEntry entry = zipInfo.getEntry(key);
            InputStream in = zipInfo.getInputStream(entry);
            File entryDest = new File(destDir, entry.getName());
            entryDest.getParentFile().mkdirs();
            if (!entry.isDirectory()) {
                OutputStream out = new FileOutputStream(new File(destDir, entry.getName()));
                try {
                    IOUtils.copy(in, out);
                    out.flush();
                    if (monitor != null) monitor.worked(1);
                } finally {
                    IOUtils.closeQuietly(in);
                    IOUtils.closeQuietly(out);
                }
            }
        }
        if (monitor != null) monitor.done();
    }
public HSSFWorkbook callRules(URL urlOfExcelDataFile, RuleSource ruleSource, String excelLogSheet) throws DroolsParserException, IOException, ClassNotFoundException {
        InputStream inputFromExcel = null;
        try {
            log.info("Looking for url:" + urlOfExcelDataFile);
            inputFromExcel = urlOfExcelDataFile.openStream();
            log.info("found url:" + urlOfExcelDataFile);
        } catch (MalformedURLException e) {
            log.log(Level.SEVERE, "Malformed URL Exception Loading rules", e);
            throw e;
        } catch (IOException e) {
            log.log(Level.SEVERE, "IO Exception Loading rules", e);
            throw e;
        }
        return callRules(inputFromExcel, ruleSource, excelLogSheet);
    }
private static boolean verifyAppId(String appid) {
        try {
            String urlstr = "http://" + appid + ".appspot.com";
            URL url = new URL(urlstr);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buf = new StringBuffer();
            String line;
            while ((line = reader.readLine()) != null) {
                buf.append(line);
            }
            reader.close();
            return buf.toString().contains("snova");
        } catch (Exception e) {
        }
        return false;
    }
private static void _checkConfigFile() throws Exception {
        try {
            String filePath = getUserManagerConfigPath() + "user_manager_config.properties";
            boolean copy = false;
            File from = new java.io.File(filePath);
            if (!from.exists()) {
                Properties properties = new Properties();
                properties.put(Config.getStringProperty("ADDITIONAL_INFO_MIDDLE_NAME_PROPNAME"), Config.getStringProperty("ADDITIONAL_INFO_MIDDLE_NAME_VISIBILITY"));
                properties.put(Config.getStringProperty("ADDITIONAL_INFO_DATE_OF_BIRTH_PROPNAME"), Config.getStringProperty("ADDITIONAL_INFO_DATE_OF_BIRTH_VISIBILITY"));
                properties.put(Config.getStringProperty("ADDITIONAL_INFO_CELL_PROPNAME"), Config.getStringProperty("ADDITIONAL_INFO_CELL_VISIBILITY"));
                properties.put(Config.getStringProperty("ADDITIONAL_INFO_CATEGORIES_PROPNAME"), Config.getStringProperty("ADDITIONAL_INFO_CATEGORIES_VISIBILITY"));
                Company comp = PublicCompanyFactory.getDefaultCompany();
                int numberGenericVariables = Config.getIntProperty("MAX_NUMBER_VARIABLES_TO_SHOW");
                for (int i = 1; i <= numberGenericVariables; i++) {
                    properties.put(LanguageUtil.get(comp.getCompanyId(), comp.getLocale(), "user.profile.var" + i).replace(" ", "_"), Config.getStringProperty("ADDITIONAL_INFO_DEFAULT_VISIBILITY"));
                }
                try {
                    properties.store(new java.io.FileOutputStream(filePath), null);
                } catch (Exception e) {
                    Logger.error(UserManagerPropertiesFactory.class, e.getMessage(), e);
                }
                from = new java.io.File(filePath);
                copy = true;
            }
            String tmpFilePath = UtilMethods.getTemporaryDirPath() + "user_manager_config_properties.tmp";
            File to = new java.io.File(tmpFilePath);
            if (!to.exists()) {
                to.createNewFile();
                copy = true;
            }
            if (copy) {
                FileChannel srcChannel = new FileInputStream(from).getChannel();
                FileChannel dstChannel = new FileOutputStream(to).getChannel();
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                srcChannel.close();
                dstChannel.close();
            }
        } catch (IOException e) {
            Logger.error(UserManagerPropertiesFactory.class, "_checkLanguagesFiles:Property File Copy Failed " + e, e);
        }
    }
public static void _save(PortletRequest req, PortletResponse res, PortletConfig config, ActionForm form) throws Exception {
        try {
            String filePath = getUserManagerConfigPath() + "user_manager_config.properties";
            String tmpFilePath = UtilMethods.getTemporaryDirPath() + "user_manager_config_properties.tmp";
            File from = new java.io.File(tmpFilePath);
            from.createNewFile();
            File to = new java.io.File(filePath);
            to.createNewFile();
            FileChannel srcChannel = new FileInputStream(from).getChannel();
            FileChannel dstChannel = new FileOutputStream(to).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (NonWritableChannelException we) {
        } catch (IOException e) {
            Logger.error(UserManagerPropertiesFactory.class, "Property File save Failed " + e, e);
        }
        SessionMessages.add(req, "message", "message.usermanager.display.save");
    }
public void saveUploadFile(String toFileName, UploadFile uploadFile, SysConfig sysConfig) throws IOException {
        OutputStream bos = new FileOutputStream(toFileName);
        IOUtils.copy(uploadFile.getInputStream(), bos);
        if (sysConfig.isAttachImg(uploadFile.getFileName()) && sysConfig.getReduceAttachImg() == 1) {
            ImgUtil.reduceImg(toFileName, toFileName + Constant.IMG_SMALL_FILEPREFIX, sysConfig.getReduceAttachImgSize(), sysConfig.getReduceAttachImgSize(), 1);
        }
    }