semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void run(IAction action) {
        Shell shell = new Shell();
        GraphicalViewer viewer = new ScrollingGraphicalViewer();
        viewer.createControl(shell);
        viewer.setEditDomain(new DefaultEditDomain(null));
        viewer.setRootEditPart(new ScalableFreeformRootEditPart());
        viewer.setEditPartFactory(new GraphicalPartFactory());
        viewer.setContents(getContents());
        viewer.flush();
        int printMode = new PrintModeDialog(shell).open();
        if (printMode == -1) return;
        PrintDialog dialog = new PrintDialog(shell, SWT.NULL);
        PrinterData data = dialog.open();
        if (data != null) {
            PrintGraphicalViewerOperation op = new PrintGraphicalViewerOperation(new Printer(data), viewer);
            op.setPrintMode(printMode);
            op.run(selectedFile.getName());
        }
    }
private ExamModel(URL urlQuestions) throws IOException, DataCoherencyException {
        BufferedReader in = new BufferedReader(new InputStreamReader(urlQuestions.openStream()));
        String line;
        questions = new ArrayList<Question>();
        questionsMap = new HashMap<String, Question>();
        in = new BufferedReader(new InputStreamReader(urlQuestions.openStream(), "UTF-8"));
        int questionNumber = 0;
        Question question;
        String questText = "";
        String hash = "";
        int lookingFor = ExamModel.READING_HASH;
        while ((line = in.readLine()) != null) {
            switch(lookingFor) {
                case ExamModel.READING_HASH:
                    if (line.length() == 0 || line.trim().length() == 0) continue;
                    hash = line;
                    questionNumber++;
                    lookingFor = ExamModel.READING_QUESTION;
                    break;
                case ExamModel.READING_QUESTION:
                    if (line.equals("--")) {
                        question = new Question(questionNumber, hash, questText);
                        questions.add(question);
                        questionsMap.put(question.getHash(), question);
                        questText = "";
                        hash = null;
                        lookingFor = ExamModel.READING_HASH;
                    } else {
                        questText = questText.concat(line + Constants.nl);
                    }
                    break;
                default:
                    throw new DataCoherencyException("Neočekávaný konec souboru!");
            }
        }
        questions.trimToSize();
        in.close();
    }
@Override
    protected int run(CmdLineParser parser) {
        final List<String> args = parser.getRemainingArgs();
        if (args.isEmpty()) {
            System.err.println("summarysort :: WORKDIR not given.");
            return 3;
        }
        if (args.size() == 1) {
            System.err.println("summarysort :: INPATH not given.");
            return 3;
        }
        final String outS = (String) parser.getOptionValue(outputDirOpt);
        final Path wrkDir = new Path(args.get(0)), in = new Path(args.get(1)), out = outS == null ? null : new Path(outS);
        final boolean verbose = parser.getBoolean(verboseOpt);
        final Configuration conf = getConf();
        final Timer t = new Timer();
        try {
            @SuppressWarnings("deprecation") final int maxReduceTasks = new JobClient(new JobConf(conf)).getClusterStatus().getMaxReduceTasks();
            conf.setInt("mapred.reduce.tasks", Math.max(1, maxReduceTasks * 9 / 10));
            final Job job = sortOne(conf, in, wrkDir, "summarysort", "");
            System.out.printf("summarysort :: Waiting for job completion...\n");
            t.start();
            if (!job.waitForCompletion(verbose)) {
                System.err.println("summarysort :: Job failed.");
                return 4;
            }
            System.out.printf("summarysort :: Job complete in %d.%03d s.\n", t.stopS(), t.fms());
        } catch (IOException e) {
            System.err.printf("summarysort :: Hadoop error: %s\n", e);
            return 4;
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        if (out != null) try {
            System.out.println("summarysort :: Merging output...");
            t.start();
            final FileSystem srcFS = wrkDir.getFileSystem(conf);
            final FileSystem dstFS = out.getFileSystem(conf);
            final OutputStream outs = dstFS.create(out);
            final FileStatus[] parts = srcFS.globStatus(new Path(wrkDir, in.getName() + "-[0-9][0-9][0-9][0-9][0-9][0-9]*"));
            {
                int i = 0;
                final Timer t2 = new Timer();
                for (final FileStatus part : parts) {
                    t2.start();
                    final InputStream ins = srcFS.open(part.getPath());
                    IOUtils.copyBytes(ins, outs, conf, false);
                    ins.close();
                    System.out.printf("summarysort :: Merged part %d in %d.%03d s.\n", ++i, t2.stopS(), t2.fms());
                }
            }
            for (final FileStatus part : parts) srcFS.delete(part.getPath(), false);
            outs.write(BlockCompressedStreamConstants.EMPTY_GZIP_BLOCK);
            outs.close();
            System.out.printf("summarysort :: Merging complete in %d.%03d s.\n", t.stopS(), t.fms());
        } catch (IOException e) {
            System.err.printf("summarysort :: Output merging failed: %s\n", e);
            return 5;
        }
        return 0;
    }
InputStream createInputStream(FileInfo fi) throws IOException, MalformedURLException {
        if (fi.inputStream != null) return fi.inputStream; else if (fi.url != null && !fi.url.equals("")) return new URL(fi.url + fi.fileName).openStream(); else {
            File f = new File(fi.directory + fi.fileName);
            if (f == null || f.isDirectory()) return null; else {
                InputStream is = new FileInputStream(f);
                if (fi.compression >= FileInfo.LZW) is = new RandomAccessStream(is);
                return is;
            }
        }
    }
public static AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException {
        InputStream inputStream = null;
        if (useragent != null) {
            URLConnection myCon = url.openConnection();
            myCon.setUseCaches(false);
            myCon.setDoInput(true);
            myCon.setDoOutput(true);
            myCon.setAllowUserInteraction(false);
            myCon.setRequestProperty("User-Agent", useragent);
            myCon.setRequestProperty("Accept", "*/*");
            myCon.setRequestProperty("Icy-Metadata", "1");
            myCon.setRequestProperty("Connection", "close");
            inputStream = new BufferedInputStream(myCon.getInputStream());
        } else {
            inputStream = new BufferedInputStream(url.openStream());
        }
        try {
            if (DEBUG == true) {
                System.err.println("Using AppletVorbisSPIWorkaround to get codec AudioFileFormat(url)");
            }
            return getAudioFileFormat(inputStream);
        } finally {
            inputStream.close();
        }
    }
public final String encrypt(String input) throws Exception {
        try {
            MessageDigest messageDigest = (MessageDigest) MessageDigest.getInstance(algorithm).clone();
            messageDigest.reset();
            messageDigest.update(input.getBytes());
            String output = convert(messageDigest.digest());
            return output;
        } catch (Throwable ex) {
            if (logger.isDebugEnabled()) {
                logger.debug("Fatal Error while digesting input string", ex);
            }
        }
        return input;
    }
private String writeInputStreamToString(InputStream stream) {
        StringWriter stringWriter = new StringWriter();
        try {
            IOUtils.copy(stream, stringWriter);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String namespaces = stringWriter.toString().trim();
        return namespaces;
    }
private void writeInputStreamToFile(InputStream stream, File file) {
        try {
            FileOutputStream fOut = new FileOutputStream(file);
            IOUtils.copy(stream, fOut);
            fOut.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void createTempFile(String resourceName) throws IOException {
        InputStream input = Log4jImportCallableTest.class.getResourceAsStream(resourceName);
        if (input == null) {
            fail("Couldn't resolve resource '" + resourceName + "'!");
        }
        inputFile = File.createTempFile("Import", "test");
        inputFile.delete();
        FileOutputStream output = new FileOutputStream(inputFile);
        IOUtils.copyLarge(input, output);
        IOUtilities.closeQuietly(output);
    }
@Override
        public Class<?> loadClass(final String name) throws ClassNotFoundException {
            final String baseName = StringUtils.substringBefore(name, "$");
            if (baseName.startsWith("java") && !whitelist.contains(baseName) && !additionalWhitelist.contains(baseName)) {
                throw new NoClassDefFoundError(name + " is a restricted class for GAE");
            }
            if (!name.startsWith("com.gargoylesoftware")) {
                return super.loadClass(name);
            }
            super.loadClass(name);
            final InputStream is = getResourceAsStream(name.replaceAll("\\.", "/") + ".class");
            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
            try {
                IOUtils.copy(is, bos);
                final byte[] bytes = bos.toByteArray();
                return defineClass(name, bytes, 0, bytes.length);
            } catch (final IOException e) {
                throw new RuntimeException(e);
            }
        }
public static Dictionary getDefaultConfig(BundleContext bc) {
        final Dictionary config = new Hashtable();
        config.put(HttpConfig.HTTP_ENABLED_KEY, getPropertyAsBoolean(bc, "org.knopflerfish.http.enabled", "true"));
        config.put(HttpConfig.HTTPS_ENABLED_KEY, getPropertyAsBoolean(bc, "org.knopflerfish.http.secure.enabled", "true"));
        config.put(HttpConfig.HTTP_PORT_KEY, getPropertyAsInteger(bc, "org.osgi.service.http.port", HTTP_PORT_DEFAULT));
        config.put(HttpConfig.HTTPS_PORT_KEY, getPropertyAsInteger(bc, "org.osgi.service.http.secure.port", HTTPS_PORT_DEFAULT));
        config.put(HttpConfig.HOST_KEY, getPropertyAsString(bc, "org.osgi.service.http.hostname", ""));
        Properties mimeProps = new Properties();
        try {
            mimeProps.load(HttpConfig.class.getResourceAsStream("/mime.default"));
            String propurl = getPropertyAsString(bc, "org.knopflerfish.http.mime.props", "");
            if (propurl.length() > 0) {
                URL url = new URL(propurl);
                Properties userMimeProps = new Properties();
                userMimeProps.load(url.openStream());
                Enumeration e = userMimeProps.keys();
                while (e.hasMoreElements()) {
                    String key = (String) e.nextElement();
                    mimeProps.put(key, userMimeProps.getProperty(key));
                }
            }
        } catch (MalformedURLException ignore) {
        } catch (IOException ignore) {
        }
        Vector mimeVector = new Vector(mimeProps.size());
        Enumeration e = mimeProps.keys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            mimeVector.addElement(new String[] { key, mimeProps.getProperty(key) });
        }
        config.put(HttpConfig.MIME_PROPS_KEY, mimeVector);
        config.put(HttpConfig.SESSION_TIMEOUT_KEY, getPropertyAsInteger(bc, "org.knopflerfish.http.session.timeout.default", 1200));
        config.put(HttpConfig.CONNECTION_TIMEOUT_KEY, getPropertyAsInteger(bc, "org.knopflerfish.http.connection.timeout", 30));
        config.put(HttpConfig.CONNECTION_MAX_KEY, getPropertyAsInteger(bc, "org.knopflerfish.http.connection.max", 50));
        config.put(HttpConfig.DNS_LOOKUP_KEY, getPropertyAsBoolean(bc, "org.knopflerfish.http.dnslookup", "false"));
        config.put(HttpConfig.RESPONSE_BUFFER_SIZE_DEFAULT_KEY, getPropertyAsInteger(bc, "org.knopflerfish.http.response.buffer.size.default", 16384));
        config.put(HttpConfig.DEFAULT_CHAR_ENCODING_KEY, getPropertyAsString(bc, HttpConfig.DEFAULT_CHAR_ENCODING_KEY, "ISO-8859-1"));
        config.put(HttpConfig.REQ_CLIENT_AUTH_KEY, getPropertyAsBoolean(bc, "org.knopflerfish.http.req.client.auth", "false"));
        return config;
    }
private void importDocument(String path, boolean detectParagraphs, Parser parser, ReadingAnnotationFilter filter, String encoding) {
        try {
            Reader in = null;
            int contentlength = 0;
            if (JGloss.messages.getString("encodings.default").equals(encoding)) encoding = null;
            String title = "";
            try {
                URL url = new URL(path);
                URLConnection c = url.openConnection();
                contentlength = c.getContentLength();
                String enc = c.getContentEncoding();
                InputStream is = new BufferedInputStream(c.getInputStream());
                if (encoding != null) in = new InputStreamReader(is, encoding); else {
                    in = CharacterEncodingDetector.getReader(is, enc);
                    encoding = ((InputStreamReader) in).getEncoding();
                }
                title = url.getFile();
                if (title == null || title.length() == 0) title = path;
            } catch (MalformedURLException ex) {
                File f = new File(path);
                contentlength = (int) f.length();
                title = f.getName();
                if (title.toLowerCase().endsWith("htm") || title.toLowerCase().endsWith("html")) {
                }
                InputStream is = new BufferedInputStream(new FileInputStream(path));
                if (encoding != null) in = new InputStreamReader(is, encoding); else {
                    in = CharacterEncodingDetector.getReader(is);
                    encoding = ((InputStreamReader) in).getEncoding();
                }
            }
            importFromReader(in, detectParagraphs, path, title, filter, parser, CharacterEncodingDetector.guessLength(contentlength, encoding));
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showConfirmDialog(this, JGloss.messages.getString("error.import.exception", new Object[] { path, ex.getClass().getName(), ex.getLocalizedMessage() }), JGloss.messages.getString("error.import.title"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
            if (model.getDocumentName() == null) this.dispose();
        }
    }
@Override
        public void testAction(ITestThread testThread) throws Throwable {
            try {
                final InputStream urlIn = new URL("http://jdistunit.sourceforge.net").openStream();
                final int availableBytes = urlIn.available();
                if (0 == availableBytes) {
                    throw new IllegalStateException("Zero bytes on target host.");
                }
                in = new BufferedReader(new InputStreamReader(urlIn));
                String line;
                while (null != (line = in.readLine())) {
                    page.append(line);
                    page.append('\n');
                    if (0 != lineDelay) {
                        OS.sleep(lineDelay);
                    }
                    if (null != testThread && testThread.isActionStopped()) {
                        break;
                    }
                }
            } finally {
                if (null != in) {
                    in.close();
                    in = null;
                }
            }
        }
@Override
    protected String getRawPage(String url) throws IOException {
        HttpClient httpClient = new HttpClient();
        String proxyHost = config.getString("proxy.host"), proxyPortString = config.getString("proxy.port");
        if (proxyHost != null && proxyPortString != null) {
            int proxyPort = -1;
            try {
                proxyPort = Integer.parseInt(proxyPortString);
            } catch (NumberFormatException e) {
            }
            if (proxyPort != -1) {
                httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
            }
        }
        GetMethod urlGet = new GetMethod(url);
        urlGet.setRequestHeader("Accept-Encoding", "");
        urlGet.setRequestHeader("User-Agent", "Mozilla/5.0");
        int retCode;
        if ((retCode = httpClient.executeMethod(urlGet)) != HttpStatus.SC_OK) {
            throw new RuntimeException("Unexpected HTTP code: " + retCode);
        }
        String encoding = null;
        Header contentType = urlGet.getResponseHeader("Content-Type");
        if (contentType != null) {
            String contentTypeString = contentType.toString();
            int i = contentTypeString.indexOf("charset=");
            if (i != -1) {
                encoding = contentTypeString.substring(i + "charset=".length()).trim();
            }
        }
        boolean gzipped = false;
        Header contentEncoding = urlGet.getResponseHeader("Content-Encoding");
        if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
            gzipped = true;
        }
        byte[] htmlData;
        try {
            InputStream in = gzipped ? new GZIPInputStream(urlGet.getResponseBodyAsStream()) : urlGet.getResponseBodyAsStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            IOUtils.copy(in, out);
            htmlData = out.toByteArray();
            in.close();
        } finally {
            urlGet.releaseConnection();
        }
        if (encoding == null) {
            Matcher m = Pattern.compile("(?i)<meta[^>]*charset=(([^\"]+\")|(\"[^\"]+\"))").matcher(new String(htmlData));
            if (m.find()) {
                encoding = m.group(1).trim().replace("\"", "");
            }
        }
        if (encoding == null) {
            encoding = "UTF-8";
        }
        return new String(htmlData, encoding);
    }
public final void copyFile(final File fromFile, final File toFile) throws IOException {
        this.createParentPathIfNeeded(toFile);
        final FileChannel sourceChannel = new FileInputStream(fromFile).getChannel();
        final FileChannel targetChannel = new FileOutputStream(toFile).getChannel();
        final long sourceFileSize = sourceChannel.size();
        sourceChannel.transferTo(0, sourceFileSize, targetChannel);
    }
public void writeToStream(String urlString, OutputStream os) {
        BufferedInputStream input = null;
        try {
            URL url = new URL(urlString);
            System.out.println("Opening stream:" + url.toString());
            input = new BufferedInputStream(url.openStream(), 4 * 1024 * 1024);
            byte[] data = new byte[102400];
            int read;
            while ((read = input.read(data)) != -1) {
                os.write(data, 0, read);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
public static String encode(String str) {
        String md5Str = null;
        try {
            MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
            digest.update(str.getBytes("UTF8"));
            byte[] hash = digest.digest();
            md5Str = "";
            for (int i = 0; i < hash.length; i++) {
                md5Str += Integer.toHexString((0x000000ff & hash[i]) | 0xffffff00).substring(6);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return md5Str;
    }
public static void insertDocumentToURL(String file, String target) throws IOException {
        InputStream is = null;
        OutputStream os = null;
        try {
            is = new FileInputStream(file);
            final URL url = new URL(target);
            final URLConnection connection = url.openConnection();
            os = connection.getOutputStream();
            TestTools.copyStream(is, os);
        } finally {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
        }
    }
public static void fileCopy(String from_name, String to_name) throws IOException {
        File fromFile = new File(from_name);
        File toFile = new File(to_name);
        if (fromFile.equals(toFile)) abort("cannot copy on itself: " + from_name);
        if (!fromFile.exists()) abort("no such currentSourcepartName file: " + from_name);
        if (!fromFile.isFile()) abort("can't copy directory: " + from_name);
        if (!fromFile.canRead()) abort("currentSourcepartName file is unreadable: " + from_name);
        if (toFile.isDirectory()) toFile = new File(toFile, fromFile.getName());
        if (toFile.exists()) {
            if (!toFile.canWrite()) abort("destination file is unwriteable: " + to_name);
        } else {
            String parent = toFile.getParent();
            if (parent == null) abort("destination directory doesn't exist: " + parent);
            File dir = new File(parent);
            if (!dir.exists()) abort("destination directory doesn't exist: " + parent);
            if (dir.isFile()) abort("destination is not a directory: " + parent);
            if (!dir.canWrite()) abort("destination directory is unwriteable: " + parent);
        }
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytes_read;
            while ((bytes_read = from.read(buffer)) != -1) to.write(buffer, 0, bytes_read);
        } finally {
            if (from != null) try {
                from.close();
            } catch (IOException e) {
                ;
            }
            if (to != null) try {
                to.close();
            } catch (IOException e) {
                ;
            }
        }
    }