예제 #1
1
 // Essentially links an InputStream to the proper channels in the log box.
 private static void printOutput(InputStream in, SimpleAttributeSet set) {
   int i = 0;
   String s = "";
   try {
     while ((i = in.read()) != -1) {
       s += (char) i;
       // print(, set);
     }
   } catch (IOException io) {
     println("Error: IOException when reading InputStream " + in.toString(), progErr);
   }
   println(s);
 }
예제 #2
0
파일: Signer.java 프로젝트: JSlain/bnd
 private void digest(MessageDigest[] algorithms, Resource r) throws Exception {
   InputStream in = r.openInputStream();
   byte[] data = new byte[BUFFER_SIZE];
   int size = in.read(data);
   while (size > 0) {
     for (int a = 0; a < algorithms.length; a++) {
       if (algorithms[a] != null) {
         algorithms[a].update(data, 0, size);
       }
     }
     size = in.read(data);
   }
 }
예제 #3
0
 /**
  * Checks if a given file exists and, if not, create it by copying a default template from
  * resources; used to create default conf files.
  *
  * @param file The path of the file that needs to exist
  * @param template The path of the template for the file
  */
 public static void ensureFileExists(final String file, final String template) {
   if (LAUNCHED_FROM_JAR && !Files.exists(Paths.get(file))) {
     if (Debug.on) printDebug("[Meta] " + file + " does not exist: creating a default one.");
     InputStream stream = Meta.class.getResourceAsStream(template);
     if (stream == null) {
       printDebug(
           "[ WARNING ] template for "
               + template
               + " not found. Won't create a default "
               + file
               + ".");
     } else {
       int readBytes;
       byte[] buffer = new byte[4096];
       try (OutputStream outStream = new FileOutputStream(new File(file))) {
         while ((readBytes = stream.read(buffer)) > 0) {
           outStream.write(buffer, 0, readBytes);
         }
         if (Debug.on)
           printDebug("[Meta] created default file " + file + " from " + template + ".");
       } catch (IOException e) {
         e.printStackTrace();
       } finally {
         try {
           stream.close();
         } catch (IOException ignore) {
         }
       }
     }
   } else {
     if (Meta.LAUNCHED_FROM_JAR && Debug.on) printDebug("[Meta] file exists: " + file + ".");
   }
 }
 private int readByte() {
   if (lenbuf == -1) throw new InputMismatchException();
   if (ptrbuf >= lenbuf) {
     ptrbuf = 0;
     try {
       lenbuf = in.read(inbuf);
     } catch (IOException e) {
       throw new InputMismatchException();
     }
     if (lenbuf <= 0) return -1;
   }
   return inbuf[ptrbuf++];
 }