semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void copy(File sourceFile, File destinationFile) {
        try {
            if (((sourceFile == null) && (destinationFile == null)) || ((sourceFile == null) || (destinationFile == null))) {
                System.out.println("sourceFile & destinationFile is null");
                System.exit(-1);
            }
            if (sourceFile.isDirectory()) {
                File[] tmp = sourceFile.listFiles();
                File f;
                for (int i = 0; i < tmp.length; i++) {
                    f = new File(destinationFile.getAbsolutePath() + File.separator + tmp[i].getName());
                    f.getParentFile().mkdirs();
                    copy(tmp[i], f);
                }
            } else {
                System.out.println("\nCopy from: " + sourceFile + "\n\n     to: " + destinationFile);
                FileChannel source = new FileInputStream(sourceFile).getChannel();
                FileChannel destination = new FileOutputStream(destinationFile).getChannel();
                destination.transferFrom(source, 0, source.size());
                source.close();
                destination.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static byte[] downloadHttpFile(String url) throws IOException {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        int responseCode = conn.getResponseCode();
        if (responseCode != HttpURLConnection.HTTP_OK) throw new IOException("Invalid HTTP response: " + responseCode + " for url " + conn.getURL());
        InputStream in = conn.getInputStream();
        try {
            return Utilities.getInputBytes(in);
        } finally {
            in.close();
        }
    }
public static void copyFile(File source, File target) throws IOException {
        FileChannel in = (new FileInputStream(source)).getChannel();
        FileChannel out = (new FileOutputStream(target)).getChannel();
        in.transferTo(0, source.length(), out);
        in.close();
        out.close();
    }
private boolean loadSymbol(QuoteCache quoteCache, Symbol symbol, TradingDate startDate, TradingDate endDate) {
        boolean success = true;
        String URLString = constructURL(symbol, startDate, endDate);
        PreferencesManager.ProxyPreferences proxyPreferences = PreferencesManager.loadProxySettings();
        try {
            URL url;
            url = new URL(URLString);
            InputStreamReader input = new InputStreamReader(url.openStream());
            BufferedReader bufferedInput = new BufferedReader(input);
            String line;
            while ((line = bufferedInput.readLine()) != null) {
                Class cl = null;
                Constructor cnst = null;
                QuoteFilter filter = null;
                try {
                    cl = Class.forName("org.mov.quote." + name + "QuoteFilter");
                    try {
                        cnst = cl.getConstructor(new Class[] { Symbol.class });
                    } catch (SecurityException e2) {
                        e2.printStackTrace();
                    } catch (NoSuchMethodException e2) {
                        e2.printStackTrace();
                    }
                    try {
                        filter = (QuoteFilter) cnst.newInstance(new Object[] { symbol });
                    } catch (IllegalArgumentException e3) {
                        e3.printStackTrace();
                    } catch (InstantiationException e3) {
                        e3.printStackTrace();
                    } catch (IllegalAccessException e3) {
                        e3.printStackTrace();
                    } catch (InvocationTargetException e3) {
                        e3.printStackTrace();
                    }
                } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();
                }
                Quote quote = filter.toQuote(line);
                if (quote != null) quoteCache.load(quote);
            }
            bufferedInput.close();
        } catch (BindException e) {
            DesktopManager.showErrorMessage(Locale.getString("UNABLE_TO_CONNECT_ERROR", e.getMessage()));
            success = false;
        } catch (ConnectException e) {
            DesktopManager.showErrorMessage(Locale.getString("UNABLE_TO_CONNECT_ERROR", e.getMessage()));
            success = false;
        } catch (UnknownHostException e) {
            DesktopManager.showErrorMessage(Locale.getString("UNKNOWN_HOST_ERROR", e.getMessage()));
            success = false;
        } catch (NoRouteToHostException e) {
            DesktopManager.showErrorMessage(Locale.getString("DESTINATION_UNREACHABLE_ERROR", e.getMessage()));
            success = false;
        } catch (MalformedURLException e) {
            DesktopManager.showErrorMessage(Locale.getString("INVALID_PROXY_ERROR", proxyPreferences.host, proxyPreferences.port));
            success = false;
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
            DesktopManager.showErrorMessage(Locale.getString("ERROR_DOWNLOADING_QUOTES"));
            success = false;
        }
        return success;
    }
private void copy(File from, File to) throws IOException {
        InputStream in = new FileInputStream(from);
        OutputStream out = new FileOutputStream(to);
        byte[] line = new byte[16384];
        int bytes = -1;
        while ((bytes = in.read(line)) != -1) out.write(line, 0, bytes);
        in.close();
        out.close();
    }
public void run() {
        URL url;
        InputSource i;
        Message m = ThemeListActivity.FeaturedThemesProgressHandler.obtainMessage();
        try {
            url = new URL(mUrl);
            i = new InputSource(url.openStream());
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            FeaturedThemesHandler fth = new FeaturedThemesHandler();
            xr.setContentHandler(fth);
            xr.parse(i);
            m.obj = fth.getParsedData();
        } catch (MalformedURLException e) {
            m.obj = e.toString();
            Log.e(TAG, "Malformed URL!", e);
        } catch (IOException e) {
            m.obj = e.toString();
            Log.e(TAG, "Exception on opening Input Stream", e);
        } catch (ParserConfigurationException e) {
            m.obj = e.toString();
            Log.e(TAG, "Exception on parsing XML File", e);
        } catch (SAXException e) {
            m.obj = e.toString();
            Log.e(TAG, "Exception while creating SAXParser", e);
        }
        ThemeListActivity.FeaturedThemesProgressHandler.sendMessage(m);
    }
private void parse() throws Exception {
        BufferedReader br = null;
        InputStream httpStream = null;
        URL fileURL = new URL(url);
        URLConnection urlConnection = fileURL.openConnection();
        httpStream = urlConnection.getInputStream();
        br = new BufferedReader(new InputStreamReader(httpStream, "UTF-8"));
        String ligne;
        String post;
        String date;
        String titre;
        String resume;
        String url2DL;
        while ((ligne = br.readLine()) != null) {
            if (ligne.indexOf("div class=\"post\" id=\"post") != -1) {
                post = null;
                date = null;
                titre = null;
                try {
                    post = ligne.substring(ligne.indexOf("post-") + 5, ligne.indexOf("\"", ligne.indexOf("post-")));
                    ligne = br.readLine();
                    date = ligne.substring(ligne.indexOf("<div class=\"date\"><span>") + 24);
                    date = date.replaceAll("</span>", "").replaceAll("</div>", "").trim();
                    log.info("Post   : " + post + " du " + date);
                    ligne = br.readLine();
                    ligne = br.readLine();
                    titre = ligne.substring(ligne.indexOf(">", ligne.indexOf("title")) + 1, ligne.indexOf("</a>"));
                    titre = titre.replaceAll("&#8217;", "'").replaceAll("&#8220;", "\"").replaceAll("&#8221;", "\"");
                    url2DL = ligne.substring(ligne.indexOf("<a href=\"") + 9, ligne.indexOf("/\"")).trim();
                    url2DL = url2DL.replace("mega-films.net", "mega-protect.com") + ".php";
                    log.info("Titre  : " + titre);
                    log.info("To DL  : " + url2DL);
                    ligne = br.readLine();
                    ligne = br.readLine();
                    ligne = br.readLine();
                    ligne = br.readLine();
                    ligne = br.readLine();
                    ligne = br.readLine();
                    ligne = br.readLine();
                    resume = ligne.substring(ligne.indexOf("<em>") + 4, ligne.indexOf("</em>"));
                    resume = resume.replaceAll("&#8217;", "'").replaceAll("&#8220;", "\"").replaceAll("&#8221;", "\"");
                    log.info("Resume : " + resume);
                } catch (Exception e) {
                    log.error("ERREUR : Le film n'a pas pu etre parse...");
                }
                log.info("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
            }
        }
    }
@Override
    protected void parseContent(StreamLimiter streamLimiter, LanguageEnum lang) throws IOException {
        File tempFile = File.createTempFile("oss", ".pptx");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(tempFile);
            IOUtils.copy(streamLimiter.getNewInputStream(), fos);
            fos.close();
        } catch (IOException e) {
            if (fos != null) IOUtils.closeQuietly(fos);
            throw e;
        }
        try {
            XSLFSlideShow pptSlideShow = new XSLFSlideShow(tempFile.getAbsolutePath());
            XSLFPowerPointExtractor poiExtractor = new XSLFPowerPointExtractor(pptSlideShow);
            CoreProperties info = poiExtractor.getCoreProperties();
            if (info != null) {
                addField(ParserFieldEnum.title, info.getTitle());
                addField(ParserFieldEnum.creator, info.getCreator());
                addField(ParserFieldEnum.subject, info.getSubject());
                addField(ParserFieldEnum.description, info.getDescription());
                addField(ParserFieldEnum.keywords, info.getKeywords());
            }
            String content = poiExtractor.getText(true, true);
            addField(ParserFieldEnum.content, StringUtils.replaceConsecutiveSpaces(content, " "));
            langDetection(10000, ParserFieldEnum.content);
        } catch (OpenXML4JException e) {
            throw new IOException(e);
        } catch (XmlException e) {
            throw new IOException(e);
        }
    }
private static BundleInfo[] getBundleInfoArray(String location) throws IOException {
        URL url = new URL(location + BUNDLE_LIST_FILE);
        BufferedReader br = null;
        List<BundleInfo> list = new ArrayList<BundleInfo>();
        try {
            br = new BufferedReader(new InputStreamReader(url.openStream()));
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                int pos1 = line.indexOf('=');
                if (pos1 < 0) {
                    continue;
                }
                BundleInfo info = new BundleInfo();
                info.bundleSymbolicName = line.substring(0, pos1);
                info.location = line.substring(pos1 + 1);
                list.add(info);
            }
            if (!setBundleInfoName(location + BUNDLE_NAME_LIST_FILE + "_" + Locale.getDefault().getLanguage(), list)) {
                setBundleInfoName(location + BUNDLE_NAME_LIST_FILE, list);
            }
            return list.toArray(BUNDLE_INFO_EMPTY_ARRAY);
        } finally {
            if (br != null) {
                br.close();
            }
        }
    }
private static boolean setBundleInfoName(String location, List<BundleInfo> list) {
        try {
            URL url = new URL(location);
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            while (true) {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                int pos1 = line.indexOf('=');
                if (pos1 < 0) {
                    continue;
                }
                String bundleSymbolicName = line.substring(0, pos1);
                String bundleName = line.substring(pos1 + 1);
                for (BundleInfo info : list) {
                    if (info.bundleSymbolicName.equals(bundleSymbolicName)) {
                        info.bundleName = bundleName;
                        break;
                    }
                }
            }
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return false;
    }
public static void main(String[] args) throws IOException {
        long readfilelen = 0;
        BufferedRandomAccessFile brafReadFile, brafWriteFile;
        brafReadFile = new BufferedRandomAccessFile("C:\\WINNT\\Fonts\\STKAITI.TTF");
        readfilelen = brafReadFile.initfilelen;
        brafWriteFile = new BufferedRandomAccessFile(".\\STKAITI.001", "rw", 10);
        byte buf[] = new byte[1024];
        int readcount;
        long start = System.currentTimeMillis();
        while ((readcount = brafReadFile.read(buf)) != -1) {
            brafWriteFile.write(buf, 0, readcount);
        }
        brafWriteFile.close();
        brafReadFile.close();
        System.out.println("BufferedRandomAccessFile Copy & Write File: " + brafReadFile.filename + "    FileSize: " + java.lang.Integer.toString((int) readfilelen >> 1024) + " (KB)    " + "Spend: " + (double) (System.currentTimeMillis() - start) / 1000 + "(s)");
        java.io.FileInputStream fdin = new java.io.FileInputStream("C:\\WINNT\\Fonts\\STKAITI.TTF");
        java.io.BufferedInputStream bis = new java.io.BufferedInputStream(fdin, 1024);
        java.io.DataInputStream dis = new java.io.DataInputStream(bis);
        java.io.FileOutputStream fdout = new java.io.FileOutputStream(".\\STKAITI.002");
        java.io.BufferedOutputStream bos = new java.io.BufferedOutputStream(fdout, 1024);
        java.io.DataOutputStream dos = new java.io.DataOutputStream(bos);
        start = System.currentTimeMillis();
        for (int i = 0; i < readfilelen; i++) {
            dos.write(dis.readByte());
        }
        dos.close();
        dis.close();
        System.out.println("DataBufferedios Copy & Write File: " + brafReadFile.filename + "    FileSize: " + java.lang.Integer.toString((int) readfilelen >> 1024) + " (KB)    " + "Spend: " + (double) (System.currentTimeMillis() - start) / 1000 + "(s)");
    }
public static void copyFile(File srcFile, File dstFile) {
        logger.info("Create file : " + dstFile.getPath());
        try {
            FileChannel srcChannel = new FileInputStream(srcFile).getChannel();
            FileChannel dstChannel = new FileOutputStream(dstFile).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static void copyFromHDFSMerge(String hdfsDir, String local) throws IOException {
        rmr(local);
        File f = new File(local);
        f.getAbsoluteFile().getParentFile().mkdirs();
        HDFSDirInputStream inp = new HDFSDirInputStream(hdfsDir);
        FileOutputStream oup = new FileOutputStream(local);
        IOUtils.copyBytes(inp, oup, 65 * 1024 * 1024, true);
    }
private void serializeWithClass(Class theClass, int count, String comment) {
        for (int c = 0; c < 10; c++) {
            if (c == 9) {
                beginAction(1, "persistence write/read", count, comment);
            }
            String tempFile = ".tmp.archive";
            SerializeClassInterface theInstance = null;
            try {
                theInstance = (SerializeClassInterface) theClass.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (theInstance == null) {
                System.err.println("error: Couldn't initialize class to " + "be serialized!");
                return;
            }
            reset();
            for (int i = 0; i < count; i++) {
                try {
                    FileOutputStream fout = new FileOutputStream(tempFile);
                    BufferedOutputStream bout = new BufferedOutputStream(fout);
                    ObjectOutputStream oout = new ObjectOutputStream(bout);
                    oout.writeObject(theInstance);
                    oout.flush();
                    oout.close();
                } catch (IOException ioe) {
                    System.err.println("serializing: " + tempFile + ":" + ioe.toString());
                }
                try {
                    FileInputStream fin = new FileInputStream(tempFile);
                    BufferedInputStream bin = new BufferedInputStream(fin);
                    ObjectInputStream oin = new ObjectInputStream(bin);
                    theInstance = (SerializeClassInterface) oin.readObject();
                    oin.close();
                } catch (Exception e) {
                    System.err.println("deserializing: " + tempFile + ":" + e.toString());
                    break;
                }
                proceed();
            }
            reset();
            if (c == 9) {
                endAction();
            }
        }
    }
public static boolean insert(final PedidoSituacao pedidoSituacao) {
        int result = 0;
        final Connection c = DBConnection.getConnection();
        PreparedStatement pst = null;
        if (c == null) {
            return false;
        }
        try {
            c.setAutoCommit(false);
            final String sql = "insert into pedido_situacao (id_pedido, id_situacao, em, observacao, id_funcionario) " + "values (?, ? , now(), ?, ?) ";
            pst = c.prepareStatement(sql);
            pst.setInt(1, pedidoSituacao.getPedido().getCodigo());
            pst.setInt(2, pedidoSituacao.getSituacao().getCodigo());
            pst.setString(3, pedidoSituacao.getObservacao());
            pst.setInt(4, pedidoSituacao.getFuncionario().getCodigo());
            result = pst.executeUpdate();
            c.commit();
        } catch (final SQLException e) {
            try {
                c.rollback();
            } catch (final SQLException e1) {
                e1.printStackTrace();
            }
            System.out.println("[PedidoSituacaoDAO.insert] Erro ao inserir -> " + e.getMessage());
        } finally {
            DBConnection.closePreparedStatement(pst);
            DBConnection.closeConnection(c);
        }
        if (result > 0) {
            return true;
        } else {
            return false;
        }
    }
public String fileUpload(final ResourceType type, final String currentFolder, final String fileName, final InputStream inputStream) throws InvalidCurrentFolderException, WriteException {
        String absolutePath = getRealUserFilesAbsolutePath(RequestCycleHandler.getUserFilesAbsolutePath(ThreadLocalData.getRequest()));
        File typeDir = getOrCreateResourceTypeDir(absolutePath, type);
        File currentDir = new File(typeDir, currentFolder);
        if (!currentDir.exists() || !currentDir.isDirectory()) throw new InvalidCurrentFolderException();
        File newFile = new File(currentDir, fileName);
        File fileToSave = UtilsFile.getUniqueFile(newFile.getAbsoluteFile());
        try {
            IOUtils.copyLarge(inputStream, new FileOutputStream(fileToSave));
        } catch (IOException e) {
            throw new WriteException();
        }
        return fileToSave.getName();
    }
private void copyFile(String path) {
        try {
            File srcfile = new File(srcdir, path);
            File destfile = new File(destdir, path);
            File parent = destfile.getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            }
            FileInputStream fis = new FileInputStream(srcfile);
            FileOutputStream fos = new FileOutputStream(destfile);
            int bytes_read = 0;
            byte buffer[] = new byte[512];
            while ((bytes_read = fis.read(buffer)) != -1) {
                fos.write(buffer, 0, bytes_read);
            }
            fis.close();
            fos.close();
        } catch (IOException e) {
            throw new BuildException("Error while copying file " + path);
        }
    }
public static ArrayList<AnalyzeDefinition> read(ArrayList<String> supportedCommands, File analyzeCommands, String programAnalyzeCommands) throws ErrorMessage {
        if (analyzeCommands != null) {
            try {
                Reader fileReader = new FileReader(analyzeCommands);
                BufferedReader reader = new BufferedReader(fileReader);
                return readConfig(reader, analyzeCommands.getName(), null);
            } catch (FileNotFoundException e) {
                throw new ErrorMessage("File \"" + analyzeCommands + "\" not found");
            }
        } else if (programAnalyzeCommands != null) {
            Reader stringReader = new StringReader(programAnalyzeCommands);
            BufferedReader reader = new BufferedReader(stringReader);
            return readConfig(reader, "program response to gogui-analyze_commands", null);
        } else {
            String resource = "net/sf/gogui/gui/analyze-commands";
            URL url = ClassLoader.getSystemClassLoader().getResource(resource);
            if (url == null) return new ArrayList<AnalyzeDefinition>();
            try {
                InputStream inputStream = url.openStream();
                Reader inputStreamReader = new InputStreamReader(inputStream);
                BufferedReader reader = new BufferedReader(inputStreamReader);
                return readConfig(reader, "builtin default commands", supportedCommands);
            } catch (IOException e) {
                throw new ErrorMessage(e.getMessage());
            }
        }
    }
public void doInsertImage() {
        logger.debug(">>> Inserting image...");
        logger.debug(" fullFileName : #0", uploadedFileName);
        String fileName = uploadedFileName.substring(uploadedFileName.lastIndexOf(File.separator) + 1);
        logger.debug(" fileName : #0", fileName);
        String newFileName = System.currentTimeMillis() + "_" + fileName;
        String filePath = ImageResource.getResourceDirectory() + File.separator + newFileName;
        logger.debug(" filePath : #0", filePath);
        try {
            File file = new File(filePath);
            file.createNewFile();
            FileChannel srcChannel = null;
            FileChannel dstChannel = null;
            try {
                srcChannel = new FileInputStream(uploadedFile).getChannel();
                dstChannel = new FileOutputStream(file).getChannel();
                dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            } finally {
                closeChannel(srcChannel);
                closeChannel(dstChannel);
            }
            StringBuilder imageTag = new StringBuilder();
            imageTag.append("<img src=\"");
            imageTag.append(getRequest().getContextPath());
            imageTag.append("/seam/resource");
            imageTag.append(ImageResource.RESOURCE_PATH);
            imageTag.append("/");
            imageTag.append(newFileName);
            imageTag.append("\"/>");
            if (getQuestionDefinition().getDescription() == null) {
                getQuestionDefinition().setDescription("");
            }
            getQuestionDefinition().setDescription(getQuestionDefinition().getDescription() + imageTag);
        } catch (IOException e) {
            logger.error("Error during saving image file", e);
        }
        uploadedFile = null;
        uploadedFileName = null;
        logger.debug("<<< Inserting image...Ok");
    }