semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static java.io.ByteArrayOutputStream getFileByteStream(URL _url) {
        java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
        try {
            InputStream input = _url.openStream();
            IOUtils.copy(input, buffer);
            IOUtils.closeQuietly(input);
        } catch (Exception err) {
            throw new RuntimeException(err);
        }
        return buffer;
    }
public static void copyFile(File source, File destination) {
        if (!source.exists()) {
            return;
        }
        if ((destination.getParentFile() != null) && (!destination.getParentFile().exists())) {
            destination.getParentFile().mkdirs();
        }
        try {
            FileChannel srcChannel = new FileInputStream(source).getChannel();
            FileChannel dstChannel = new FileOutputStream(destination).getChannel();
            dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
            srcChannel.close();
            dstChannel.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
public static int best(int r, int n, int s) {
        if ((n <= 0) || (r < 0) || (r > n) || (s < 0)) return 0;
        int[] rolls = new int[n];
        for (int i = 0; i < n; i++) rolls[i] = d(s);
        boolean found;
        do {
            found = false;
            for (int x = 0; x < n - 1; x++) {
                if (rolls[x] < rolls[x + 1]) {
                    int t = rolls[x];
                    rolls[x] = rolls[x + 1];
                    rolls[x + 1] = t;
                    found = true;
                }
            }
        } while (found);
        int sum = 0;
        for (int i = 0; i < r; i++) sum += rolls[i];
        return sum;
    }
private void preprocessObjects(GeoObject[] objects) throws IOException {
        System.out.println("objects.length " + objects.length);
        for (int i = 0; i < objects.length; i++) {
            String fileName = objects[i].getPath();
            int dotindex = fileName.lastIndexOf(".");
            dotindex = dotindex < 0 ? 0 : dotindex;
            String tmp = dotindex < 1 ? fileName : fileName.substring(0, dotindex + 3) + "w";
            System.out.println("i: " + " world filename " + tmp);
            File worldFile = new File(tmp);
            if (worldFile.exists()) {
                BufferedReader worldFileReader = new BufferedReader(new InputStreamReader(new FileInputStream(worldFile)));
                if (staticDebugOn) debug("b4nextline: ");
                line = worldFileReader.readLine();
                if (staticDebugOn) debug("line: " + line);
                if (line != null) {
                    line = worldFileReader.readLine();
                    if (staticDebugOn) debug("line: " + line);
                    tokenizer = new StringTokenizer(line, " \n\t\r\"", false);
                    objects[i].setLon(Double.valueOf(tokenizer.nextToken()).doubleValue());
                    line = worldFileReader.readLine();
                    if (staticDebugOn) debug("line: " + line);
                    tokenizer = new StringTokenizer(line, " \n\t\r\"", false);
                    objects[i].setLat(Double.valueOf(tokenizer.nextToken()).doubleValue());
                }
            }
            File file = new File(objects[i].getPath());
            if (file.exists()) {
                System.out.println("object src file found ");
                int slashindex = fileName.lastIndexOf(java.io.File.separator);
                slashindex = slashindex < 0 ? 0 : slashindex;
                if (slashindex == 0) {
                    slashindex = fileName.lastIndexOf("/");
                    slashindex = slashindex < 0 ? 0 : slashindex;
                }
                tmp = slashindex < 1 ? fileName : fileName.substring(slashindex + 1, fileName.length());
                System.out.println("filename " + destinationDirectory + XPlat.fileSep + tmp);
                objects[i].setPath(tmp);
                file = new File(fileName);
                if (file.exists()) {
                    DataInputStream dataIn = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
                    DataOutputStream dataOut = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(destinationDirectory + XPlat.fileSep + tmp)));
                    System.out.println("copying to " + destinationDirectory + XPlat.fileSep + tmp);
                    for (; ; ) {
                        try {
                            dataOut.writeShort(dataIn.readShort());
                        } catch (EOFException e) {
                            break;
                        } catch (IOException e) {
                            break;
                        }
                    }
                    dataOut.close();
                }
            }
        }
    }
@Override
    @Transactional
    public FileData store(FileData data, InputStream stream) {
        try {
            FileData file = save(data);
            file.setPath(file.getGroup() + File.separator + file.getId());
            file = save(file);
            File folder = new File(PATH, file.getGroup());
            if (!folder.exists()) folder.mkdirs();
            File filename = new File(folder, file.getId() + "");
            IOUtils.copyLarge(stream, new FileOutputStream(filename));
            return file;
        } catch (IOException e) {
            throw new ServiceException("storage", e);
        }
    }
@PostConstruct
    public void init() {
        logger.info("+++++ TRACAuditChecklistWizardMB: init() start ++++++++");
        try {
            tracSectionAll = new ArrayList<TRACCriteriaCheckListItem>();
            List<TRACCriteriaCheckListItem> tracSectionA = new ArrayList<TRACCriteriaCheckListItem>();
            List<TRACCriteriaCheckListItem> tracSectionB = new ArrayList<TRACCriteriaCheckListItem>();
            List<TRACCriteriaCheckListItem> tracSectionC = new ArrayList<TRACCriteriaCheckListItem>();
            URL url = TRACAuditChecklistManagedBean.class.getResource(tracCriteriaPropertiesFileName);
            tracCriteriaCheckList = new LinkedProperties();
            tracCriteriaCheckList.load(url.openStream());
            Set<String> tmpKeys = tracCriteriaCheckList.stringPropertyNames();
            List<String> sortWrkList = new ArrayList<String>();
            sortWrkList.addAll(tmpKeys);
            sortList(sortWrkList);
            for (String key : sortWrkList) {
                String aspectCode = key.substring(aspectCodeOffsetValue);
                logger.info("aspectCode=" + aspectCode);
                if (aspectCode.startsWith("A")) {
                    if (aspectCode.equals("A")) {
                        sectionAcaption = tracCriteriaCheckList.getProperty(key);
                    } else {
                        if (aspectCode.length() == 4) {
                            tracSectionAll.add(new TRACCriteriaCheckListItem(aspectCode, tracCriteriaCheckList.getProperty(key), "", "", ""));
                        }
                    }
                } else if (aspectCode.startsWith("B")) {
                    if (aspectCode.equals("B")) {
                        sectionBcaption = tracCriteriaCheckList.getProperty(key);
                    } else {
                        if (aspectCode.length() == 4) {
                            tracSectionAll.add(new TRACCriteriaCheckListItem(aspectCode, tracCriteriaCheckList.getProperty(key), "", "", ""));
                        }
                    }
                } else if (aspectCode.startsWith("C")) {
                    if (aspectCode.equals("C")) {
                        sectionCcaption = tracCriteriaCheckList.getProperty(key);
                    } else {
                        if (aspectCode.length() == 4) {
                            tracSectionAll.add(new TRACCriteriaCheckListItem(aspectCode, tracCriteriaCheckList.getProperty(key), "", "", ""));
                        }
                    }
                } else {
                    logger.warning("offset value is wrong: 16th character must be A or B or C");
                }
            }
        } catch (FileNotFoundException ex) {
            logger.log(Level.WARNING, "specified properties file was not found", ex);
        } catch (IOException ex) {
            logger.log(Level.WARNING, "IO error occurred", ex);
        } finally {
        }
        logger.info("+++++ TRACAuditChecklistWizardMB: init() end   ++++++++");
    }
protected Document fetchResource(String method, String parameter, Locale locale, final FloodLimit limit) throws IOException, SAXException {
        return getDocument(new CachedPage(getResourceLocation(method, parameter, locale)) {

            @Override
            protected Reader openConnection(URL url) throws IOException {
                try {
                    if (limit != null) {
                        limit.acquirePermit();
                    }
                    return super.openConnection(url);
                } catch (InterruptedException e) {
                    throw new IOException(e);
                }
            }

            ;
        }.get());
    }
@Override
            protected Reader openConnection(URL url) throws IOException {
                try {
                    if (limit != null) {
                        limit.acquirePermit();
                    }
                    return super.openConnection(url);
                } catch (InterruptedException e) {
                    throw new IOException(e);
                }
            }
public AssessmentItemType getAssessmentItemType(String filename) {
        if (filename.contains(" ") && (System.getProperty("os.name").contains("Windows"))) {
            File source = new File(filename);
            String tempDir = System.getenv("TEMP");
            File dest = new File(tempDir + "/temp.xml");
            MQMain.logger.info("Importing from " + dest.getAbsolutePath());
            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);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (in != null) try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (out != null) try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                filename = tempDir + "/temp.xml";
            }
        }
        AssessmentItemType assessmentItemType = null;
        JAXBElement<?> jaxbe = null;
        try {
            XMLReader reader = XMLReaderFactory.createXMLReader();
            ChangeNamespace convertfromv2p0tov2p1 = new ChangeNamespace(reader, "http://www.imsglobal.org/xsd/imsqti_v2p0", "http://www.imsglobal.org/xsd/imsqti_v2p1");
            SAXSource source = null;
            try {
                FileInputStream fis = new FileInputStream(filename);
                InputStreamReader isr = null;
                try {
                    isr = new InputStreamReader(fis, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                }
                InputSource is = new InputSource(isr);
                source = new SAXSource(convertfromv2p0tov2p1, is);
            } catch (FileNotFoundException e) {
                MQMain.logger.error("SAX/getAssessmentItemType/file not found");
            }
            jaxbe = (JAXBElement<?>) MQModel.qtiCf.unmarshal(MQModel.imsqtiUnmarshaller, source);
            assessmentItemType = (AssessmentItemType) jaxbe.getValue();
        } catch (JAXBException e) {
            MQMain.logger.error("JAX/getAssessmentItemType", e);
        } catch (SAXException e) {
            MQMain.logger.error("SAX/getAssessmentItemType", e);
        }
        return assessmentItemType;
    }
public final int wordFrequency(String word) {
        String replWebQuery = webQuery.replaceFirst("WORDREPLACE", word);
        try {
            URL url = new URL(replWebQuery);
            String content = url.toString();
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                if (inputLine.matches(nrResultsPattern)) {
                    int fr = matchedLine(inputLine);
                    if (fr >= 0) {
                        return fr;
                    }
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }
public void store(Component component, String componentName, int currentPilot) {
        try {
            PreparedStatement psta = jdbc.prepareStatement("UPDATE component_prop " + "SET size_height = ?, size_width = ?, pos_x = ?, pos_y = ? " + "WHERE pilot_id = ? " + "AND component_name = ?");
            psta.setInt(1, component.getHeight());
            psta.setInt(2, component.getWidth());
            Point point = component.getLocation();
            psta.setInt(3, point.x);
            psta.setInt(4, point.y);
            psta.setInt(5, currentPilot);
            psta.setString(6, componentName);
            int update = psta.executeUpdate();
            if (update == 0) {
                psta = jdbc.prepareStatement("INSERT INTO component_prop " + "(size_height, size_width, pos_x, pos_y, pilot_id, component_name) " + "VALUES (?,?,?,?,?,?)");
                psta.setInt(1, component.getHeight());
                psta.setInt(2, component.getWidth());
                psta.setInt(3, point.x);
                psta.setInt(4, point.y);
                psta.setInt(5, currentPilot);
                psta.setString(6, componentName);
                psta.executeUpdate();
            }
            jdbc.commit();
        } catch (SQLException e) {
            jdbc.rollback();
            log.debug(e);
        }
    }
private void Connect() throws NpsException {
        try {
            client = new FTPClient();
            client.connect(host.hostname, host.remoteport);
            int reply = client.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                client.disconnect();
                client = null;
                nps.util.DefaultLog.error_noexception("FTP Server:" + host.hostname + "refused connection.");
                return;
            }
            client.login(host.uname, host.upasswd);
            client.enterLocalPassiveMode();
            client.setFileType(FTPClient.BINARY_FILE_TYPE);
            client.changeWorkingDirectory(host.remotedir);
        } catch (Exception e) {
            nps.util.DefaultLog.error(e);
        }
    }
public void sorter() {
        String inputLine1, inputLine2;
        String epiNames[] = new String[1000];
        String epiEpisodes[] = new String[1000];
        int lineCounter = 0;
        try {
            String pluginDir = pluginInterface.getPluginDirectoryName();
            String eplist_file = pluginDir + System.getProperty("file.separator") + "EpisodeList.txt";
            File episodeList = new File(eplist_file);
            if (!episodeList.isFile()) {
                episodeList.createNewFile();
            }
            final BufferedReader in = new BufferedReader(new FileReader(episodeList));
            while ((inputLine1 = in.readLine()) != null) {
                if ((inputLine2 = in.readLine()) != null) {
                    epiNames[lineCounter] = inputLine1;
                    epiEpisodes[lineCounter] = inputLine2;
                    lineCounter++;
                }
            }
            in.close();
            int epiLength = epiNames.length;
            for (int i = 0; i < (lineCounter); i++) {
                for (int j = 0; j < (lineCounter - 1); j++) {
                    if (epiNames[j].compareToIgnoreCase(epiNames[j + 1]) > 0) {
                        String temp = epiNames[j];
                        epiNames[j] = epiNames[j + 1];
                        epiNames[j + 1] = temp;
                        String temp2 = epiEpisodes[j];
                        epiEpisodes[j] = epiEpisodes[j + 1];
                        epiEpisodes[j + 1] = temp2;
                    }
                }
            }
            File episodeList2 = new File(eplist_file);
            BufferedWriter bufWriter = new BufferedWriter(new FileWriter(episodeList2));
            for (int i = 0; i <= lineCounter; i++) {
                if (epiNames[i] == null) {
                    break;
                }
                bufWriter.write(epiNames[i] + "\n");
                bufWriter.write(epiEpisodes[i] + "\n");
            }
            bufWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String machineInfo() {
        StringBuilder machineInfo = new StringBuilder();
        try {
            Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                NetworkInterface networkInterface = (NetworkInterface) networkInterfaces.nextElement();
                if ("eth0".equals(networkInterface.getDisplayName())) {
                    for (byte b : networkInterface.getHardwareAddress()) {
                        StringTools.appendWithDelimiter(machineInfo, String.format("%02x", b).toUpperCase(), ":");
                    }
                    machineInfo.append("\n");
                    break;
                }
            }
        } catch (IOException x) {
            System.out.println("LicenseTools.machineInfo: " + x.getMessage());
            x.printStackTrace();
        }
        if (machineInfo.length() == 0) {
            return null;
        }
        String info = machineInfo.toString();
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5", "SUN");
            messageDigest.update(info.getBytes());
            byte[] md5 = messageDigest.digest(info.getBytes());
            return new String(Base64.encodeBase64(md5));
        } catch (Exception x) {
            System.out.println("LicenseTools.machineInfo: " + x.getMessage());
            x.printStackTrace();
        }
        return null;
    }
public static void makeBackup(File dir, String sourcedir, String destinationdir, String destinationDirEnding) {
        String[] files;
        files = dir.list();
        File checkdir = new File(destinationdir + System.getProperty("file.separator") + destinationDirEnding);
        if (!checkdir.isDirectory()) {
            checkdir.mkdir();
        }
        ;
        Date date = new Date();
        long msec = date.getTime();
        checkdir.setLastModified(msec);
        File checkFile = new File(checkdir + System.getProperty("file.separator") + "azureus.config");
        if (checkFile.exists()) {
            checkFile.setLastModified(msec);
        }
        try {
            for (int i = 0; i < files.length; i++) {
                File f = new File(dir, files[i]);
                File g = new File(files[i]);
                if (f.isDirectory()) {
                } else {
                    String destinationFile = checkdir + System.getProperty("file.separator") + g;
                    String sourceFile = sourcedir + System.getProperty("file.separator") + g;
                    FileInputStream infile = new FileInputStream(sourceFile);
                    FileOutputStream outfile = new FileOutputStream(destinationFile);
                    int c;
                    while ((c = infile.read()) != -1) outfile.write(c);
                    infile.close();
                    outfile.close();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static String getWebpage(String url) {
        String content = "";
        if (!url.trim().toLowerCase().startsWith("http://")) {
            url = "http://" + url;
        }
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                content += line + "\n";
            }
            reader.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        return content;
    }
protected static final void download(String address, File localFileName) {
        OutputStream out = null;
        URLConnection conn = null;
        InputStream in = null;
        try {
            URL url = new URL(address);
            out = new BufferedOutputStream(new FileOutputStream(localFileName));
            conn = url.openConnection();
            in = conn.getInputStream();
            byte[] buffer = new byte[1024];
            int numRead;
            long numWritten = 0;
            while ((numRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, numRead);
                numWritten += numRead;
            }
            System.out.println(localFileName + "\t" + numWritten);
        } catch (Exception exception) {
            exception.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
                if (out != null) {
                    out.close();
                }
            } catch (IOException ioe) {
            }
        }
    }
public String generateFilename() {
        MessageDigest md;
        byte[] sha1hash = new byte[40];
        Random r = new Random();
        String fileName = "";
        String token = "";
        while (true) {
            token = Long.toString(Math.abs(r.nextLong()), 36) + Long.toString(System.currentTimeMillis());
            try {
                md = MessageDigest.getInstance("SHA-1");
                md.update(token.getBytes("iso-8859-1"), 0, token.length());
                sha1hash = md.digest();
            } catch (Exception e) {
                log.log(Level.WARNING, e.getMessage(), e);
            }
            fileName = convertToHex(sha1hash);
            if (!new File(Configuration.ImageUploadPath + fileName).exists()) {
                break;
            }
        }
        return fileName;
    }
@Test
    @Ignore
    public void testToJson() throws IOException {
        JsonSerializer js = new StreamingJsonSerializer(new ObjectMapper());
        BulkOperation op = js.createBulkOperation(createTestData(10000), false);
        IOUtils.copy(op.getData(), System.out);
    }
public void run() {
            try {
                putEvent(new DebugEvent("about to place HTTP request"));
                HttpGet req = new HttpGet(requestURL);
                req.addHeader("Connection", "close");
                HttpResponse httpResponse = httpClient.execute(req);
                putEvent(new DebugEvent("got response to HTTP request"));
                nonSipPort.input(new Integer(httpResponse.getStatusLine().getStatusCode()));
                HttpEntity entity = httpResponse.getEntity();
                if (entity != null) {
                    InputStream in = entity.getContent();
                    if (in != null) in.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }