Ejemplo n.º 1
0
 /**
  * Create an Internet shortcut
  *
  * @param name name of the shortcut
  * @param where location of the shortcut
  * @param target URL
  * @param icon URL (ex. http://www.server.com/favicon.ico)
  */
 public static void createInternetShortcut(String name, String where, String target, String icon) {
   try (FileWriter fw = new FileWriter(where)) {
     fw.write("[InternetShortcut]\n");
     fw.write("URL=" + target + '\n');
     if (!icon.isEmpty()) fw.write("IconFile=" + icon + '\n');
   } catch (IOException iox) {
     /**/
   }
 }
Ejemplo n.º 2
0
 private File getTempFile(String path) throws IOException {
   InputStream is = this.getClass().getResourceAsStream("/certs/" + path);
   File dest = File.createTempFile("cert-", "pem");
   LineNumberReader reader = new LineNumberReader(new InputStreamReader(is));
   FileWriter writer = new FileWriter(dest);
   try {
     String line;
     while ((line = reader.readLine()) != null) {
       writer.write(line + "\n");
     }
     return dest;
   } finally {
     writer.close();
     reader.close();
   }
 }
Ejemplo n.º 3
0
  /**
   * Write the output file with a graph format.
   *
   * @param outputFileName the output file to write to
   * @param urlToImageFileMap the map of url's to image files
   * @param edgeList the list of sources and sinks to write
   */
  public void writeDotFile(
      String outputFileName,
      Map<String, String> urlToImageFileMap,
      Map<String, Set<String>> edgeList) {

    try {

      File outputFile = new File(outputFileName);
      FileWriter fileWriter = new FileWriter(outputFile);
      fileWriter.write("digraph G {\n");
      fileWriter.write("  node [shape=box];\n");
      Set<String> urls = urlToImageFileMap.keySet();

      for (String url : urls) {
        String hashedUrl = getHashCode(url);
        String imageFileName = urlToImageFileMap.get(url);
        fileWriter.write("  " + hashedUrl + "[label=\"\" image=\"" + imageFileName + "\"];\n");
      }

      for (String url : urls) {
        Set<String> links = edgeList.get(url);
        if (links != null) {
          for (String link : links) {
            if (urls.contains(link)) {
              String hashUrlSource = getHashCode(url);
              String hashUrlSink = getHashCode(link);
              fileWriter.write("  " + hashUrlSource + " -> " + hashUrlSink + "\n");
            }
          }
        }
      }

      fileWriter.write("}\n");
      fileWriter.flush();
      fileWriter.close();
      System.out.println("Wrote results to [" + outputFileName + "]");
    } catch (Exception e) {
      System.out.println("Exception writing the results to the output file: " + e);
    }
  }
Ejemplo n.º 4
0
  @Override
  public void run() {

    ChukasaModel chukasaModel = chukasaModelManagementComponent.get(adaptiveBitrateStreaming);
    String streamPath = chukasaModel.getStreamPath();
    String tempEncPath = chukasaModel.getTempEncPath();
    int tsPacketLength = chukasaModel.getHlsConfiguration().getMpeg2TsPacketLength();

    int seqTsEnc = 0; // getSeqTsEnc();
    seqTsEnc = chukasaModel.getSeqTsEnc();
    if (chukasaModel.getChukasaSettings().getStreamingType() == StreamingType.OKKAKE) {
      seqTsEnc = chukasaModel.getSeqTsOkkake() - 1;
    }
    if (chukasaModel.isFlagLastTs()) {
      seqTsEnc = chukasaModel.getSeqTsLast();
    }

    Key sKey;
    Cipher c;
    FileOutputStream keyOut;
    FileWriter ivOut;
    FileInputStream fis;
    BufferedInputStream bis;
    FileOutputStream fos;
    CipherOutputStream cos;

    try {
      Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

      sKey = makeKey(128); // Key length is 128bit
      c = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");

      c.init(Cipher.ENCRYPT_MODE, sKey);

      // Set Key File Name at random
      String keyPre = RandomStringUtils.randomAlphabetic(10);
      keyOut = new FileOutputStream(streamPath + FILE_SEPARATOR + keyPre + seqTsEnc + ".key");

      chukasaModel.getKeyArrayList().add(keyPre);
      chukasaModel = chukasaModelManagementComponent.update(adaptiveBitrateStreaming, chukasaModel);

      byte[] keyOutByte = sKey.getEncoded();
      keyOut.write(keyOutByte);
      keyOut.close();

      byte[] iv = c.getIV();

      String ivHex = "";
      for (int i = 0; i < iv.length; i++) {
        String ivHexTmp = String.format("%02x", iv[i]).toUpperCase();
        ivHex = ivHex + ivHexTmp;
      }

      String ivPre = RandomStringUtils.randomAlphabetic(10);
      ivOut = new FileWriter(streamPath + FILE_SEPARATOR + ivPre + seqTsEnc + ".iv");
      ivOut.write(ivHex);
      ivOut.close();

      chukasaModel.getIvArrayList().add(ivHex);
      chukasaModel = chukasaModelManagementComponent.update(adaptiveBitrateStreaming, chukasaModel);

      fis =
          new FileInputStream(
              tempEncPath
                  + FILE_SEPARATOR
                  + chukasaModel.getChukasaConfiguration().getStreamFileNamePrefix()
                  + seqTsEnc
                  + chukasaModel.getHlsConfiguration().getStreamExtension());
      bis = new BufferedInputStream(fis);
      fos =
          new FileOutputStream(
              streamPath
                  + FILE_SEPARATOR
                  + chukasaModel.getChukasaConfiguration().getStreamFileNamePrefix()
                  + seqTsEnc
                  + chukasaModel.getHlsConfiguration().getStreamExtension());
      cos = new CipherOutputStream(fos, c);
      if (chukasaModel.getChukasaSettings().getStreamingType() == StreamingType.OKKAKE) {
        // TODO:
        fis =
            new FileInputStream(
                tempEncPath
                    + FILE_SEPARATOR
                    + "fileSequenceEncoded"
                    + seqTsEnc
                    + chukasaModel.getHlsConfiguration().getStreamExtension());
        bis = new BufferedInputStream(fis);
        fos =
            new FileOutputStream(
                streamPath
                    + FILE_SEPARATOR
                    + chukasaModel.getChukasaConfiguration().getStreamFileNamePrefix()
                    + seqTsEnc
                    + chukasaModel.getHlsConfiguration().getStreamExtension());
        cos = new CipherOutputStream(fos, c);
      }

      byte[] buf = new byte[tsPacketLength];

      int ch;
      while ((ch = bis.read(buf)) != -1) {
        cos.write(buf, 0, ch);
      }
      cos.close();
      fos.close();
      bis.close();
      fis.close();

    } catch (InvalidKeyException e) {
      e.printStackTrace();
    } catch (NoSuchPaddingException e) {
      e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    } catch (NoSuchProviderException e) {
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }