Beispiel #1
0
  /**
   * Load in the filesystem image. It's a big list of filenames and blocks. Return whether we should
   * "re-save" and consolidate the edit-logs
   */
  boolean loadFSImage(File fsdir, File edits) throws IOException {
    //
    // Atomic move sequence, to recover from interrupted save
    //
    File curFile = new File(fsdir, FS_IMAGE);
    File newFile = new File(fsdir, NEW_FS_IMAGE);
    File oldFile = new File(fsdir, OLD_FS_IMAGE);

    // Maybe we were interrupted between 2 and 4
    if (oldFile.exists() && curFile.exists()) {
      oldFile.delete();
      if (edits.exists()) {
        edits.delete();
      }
    } else if (oldFile.exists() && newFile.exists()) {
      // Or maybe between 1 and 2
      newFile.renameTo(curFile);
      oldFile.delete();
    } else if (curFile.exists() && newFile.exists()) {
      // Or else before stage 1, in which case we lose the edits
      newFile.delete();
    }

    //
    // Load in bits
    //
    if (curFile.exists()) {
      DataInputStream in =
          new DataInputStream(new BufferedInputStream(new FileInputStream(curFile)));
      try {
        int numFiles = in.readInt();
        for (int i = 0; i < numFiles; i++) {
          UTF8 name = new UTF8();
          name.readFields(in);
          int numBlocks = in.readInt();
          if (numBlocks == 0) {
            unprotectedAddFile(name, null);
          } else {
            Block blocks[] = new Block[numBlocks];
            for (int j = 0; j < numBlocks; j++) {
              blocks[j] = new Block();
              blocks[j].readFields(in);
            }
            unprotectedAddFile(name, blocks);
          }
        }
      } finally {
        in.close();
      }
    }

    if (edits.exists() && loadFSEdits(edits) > 0) {
      return true;
    } else {
      return false;
    }
  }
Beispiel #2
0
  @Override
  protected void parse(final byte[] raw) {

    super.parse(raw);

    // calculate fields

    // scheme
    this.scheme = getProtocol().split("/")[0].toLowerCase();

    // secure
    this.secure = (getScheme().equals("https"));

    // host and port
    final String[] hostport = getHeader("host").split(":");
    this.serverName = hostport[0];
    this.serverPort = Integer.parseInt(hostport[1]);

    // servlet path: handler path with out the pattern
    final int posPatternStart = getHeader(H_PATTERN).indexOf('(');
    if (posPatternStart == -1) {
      this.servletPath = getHeader(H_PATTERN);
    } else {
      this.servletPath = getHeader(H_PATTERN).substring(0, posPatternStart);
    }

    // path info: URI - PATTERN
    this.pathinfo = getRequestURI().substring(getServletPath().length());

    // requestURL
    final StringBuilder requestURL = new StringBuilder();
    requestURL.append(getScheme());
    requestURL.append("://");
    requestURL.append(getServerName());
    if ((getScheme().equals("http") && getServerPort() != 80)
        || (getScheme().equals("https") && getServerPort() != 443)) {
      requestURL.append(':');
      requestURL.append(getServerPort());
    }
    requestURL.append(getRequestURI());
    this.requestURL = requestURL.toString();

    // parameters
    if (getQueryString() != null && getQueryString().length() > 0) {
      try {
        final String[] paramEntries = getQueryString().split("&");
        for (final String entry : paramEntries) {
          final String[] kv = entry.split("=");
          final String key = URLDecoder.decode(kv[0], UTF8.name());
          final String value = URLDecoder.decode(kv[1], UTF8.name());
          addParameter(key, value);
        }
      } catch (final UnsupportedEncodingException x) {
        throw new InternalError("JVM does not support " + UTF8.name());
      }
    }
  }
 @SuppressWarnings("deprecation")
 public void write(DataOutput out) throws IOException {
   out.writeLong(rpcVersion);
   UTF8.writeString(out, declaringClassProtocolName);
   UTF8.writeString(out, methodName);
   out.writeLong(clientVersion);
   out.writeInt(clientMethodsHash);
   out.writeInt(parameterClasses.length);
   for (int i = 0; i < parameterClasses.length; i++) {
     ObjectWritable.writeObject(out, parameters[i], parameterClasses[i], conf, true);
   }
 }
Beispiel #4
0
  /** Write a {@link Writable}, {@link String}, primitive type, or an array of the preceding. */
  public static void writeObject(
      DataOutput out, Object instance, Class declaredClass, Configuration conf) throws IOException {

    if (instance == null) { // null
      instance = new NullInstance(declaredClass, conf);
      declaredClass = Writable.class;
    }

    UTF8.writeString(out, declaredClass.getName()); // always write declared

    if (declaredClass.isArray()) { // array
      int length = Array.getLength(instance);
      out.writeInt(length);
      for (int i = 0; i < length; i++) {
        writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf);
      }

    } else if (declaredClass == String.class) { // String
      UTF8.writeString(out, (String) instance);

    } else if (declaredClass.isPrimitive()) { // primitive type

      if (declaredClass == Boolean.TYPE) { // boolean
        out.writeBoolean(((Boolean) instance).booleanValue());
      } else if (declaredClass == Character.TYPE) { // char
        out.writeChar(((Character) instance).charValue());
      } else if (declaredClass == Byte.TYPE) { // byte
        out.writeByte(((Byte) instance).byteValue());
      } else if (declaredClass == Short.TYPE) { // short
        out.writeShort(((Short) instance).shortValue());
      } else if (declaredClass == Integer.TYPE) { // int
        out.writeInt(((Integer) instance).intValue());
      } else if (declaredClass == Long.TYPE) { // long
        out.writeLong(((Long) instance).longValue());
      } else if (declaredClass == Float.TYPE) { // float
        out.writeFloat(((Float) instance).floatValue());
      } else if (declaredClass == Double.TYPE) { // double
        out.writeDouble(((Double) instance).doubleValue());
      } else if (declaredClass == Void.TYPE) { // void
      } else {
        throw new IllegalArgumentException("Not a primitive: " + declaredClass);
      }
    } else if (declaredClass.isEnum()) { // enum
      UTF8.writeString(out, ((Enum) instance).name());
    } else if (Writable.class.isAssignableFrom(declaredClass)) { // Writable
      UTF8.writeString(out, instance.getClass().getName());
      ((Writable) instance).write(out);

    } else {
      throw new IOException("Can't write: " + instance + " as " + declaredClass);
    }
  }
 public void write(DataOutput out) throws IOException {
   out.write(BASE_TYPE);
   out.writeUTF(name);
   out.writeInt(sampleStrs.size());
   for (int i = 0; i < sampleStrs.size(); i++) {
     UTF8.writeString(out, sampleStrs.get(i));
   }
   out.writeInt(tokenClassIdentifier);
   out.writeBoolean(tokenParameter != null);
   if (tokenParameter != null) {
     UTF8.writeString(out, tokenParameter);
   }
 }
 @SuppressWarnings("deprecation")
 public void readFields(DataInput in) throws IOException {
   rpcVersion = in.readLong();
   declaringClassProtocolName = UTF8.readString(in);
   methodName = UTF8.readString(in);
   clientVersion = in.readLong();
   clientMethodsHash = in.readInt();
   parameters = new Object[in.readInt()];
   parameterClasses = new Class[parameters.length];
   ObjectWritable objectWritable = new ObjectWritable();
   for (int i = 0; i < parameters.length; i++) {
     parameters[i] = ObjectWritable.readObject(in, objectWritable, this.conf);
     parameterClasses[i] = objectWritable.getDeclaredClass();
   }
 }
 public void readFields(DataInput in) throws IOException {
   // instance-specific
   this.sampleStrs = new ArrayList<String>();
   int numSamples = in.readInt();
   for (int i = 0; i < numSamples; i++) {
     sampleStrs.add(UTF8.readString(in).toString());
   }
   this.tokenClassIdentifier = in.readInt();
   if (in.readBoolean()) {
     this.tokenParameter = UTF8.readString(in);
   } else {
     this.tokenParameter = null;
   }
   this.schema = computeAvroSchema();
 }
Beispiel #8
0
 String normalizePath(UTF8 src) {
   String srcs = src.toString();
   if (srcs.length() > 1 && srcs.endsWith("/")) {
     srcs = srcs.substring(0, srcs.length() - 1);
   }
   return srcs;
 }
Beispiel #9
0
 /**
  * Decode a character according to the expected encoding.
  *
  * @param c first character of the possibly encoded character sequence
  * @param in <code>InputStream</code> with possible extra encoded characters.
  * @return decoded character
  * @throws IOException if an i/o error occurs in the underlying input stream
  */
 protected int decode(int c, InputStream in) throws IOException {
   switch (encoding) {
     case ENC_UTF8:
       c = utf8.readUtf8(c, in);
       bytesOut.write(utf8.chars_read);
       bValidChar = utf8.bValidChar;
       if (c != -1) {
         if (!bValidChar) {
           // Invalid UTF-8 char
           bfErrors |= E_BIT_INVALID_UTF8_ENCODING;
         }
       }
       break;
     case ENC_US_ASCII:
       bValidChar = (c <= 127);
       if (!bValidChar) {
         // Invalid US-ASCII char
         bfErrors |= E_BIT_INVALID_US_ASCII_CHAR;
       }
       break;
     case ENC_ISO8859_1:
       // ISO-8859-1 utilizes all 8-bits and requires no decoding.
     case ENC_RAW:
       // Raw 8-bit character needs no decoding.
     default:
       bValidChar = true;
       break;
   }
   return c;
 }
Beispiel #10
0
 public void readFields(DataInput in) throws IOException {
   methodName = UTF8.readString(in);
   parameters = new Object[in.readInt()];
   parameterClasses = new Class[parameters.length];
   ObjectWritable objectWritable = new ObjectWritable();
   for (int i = 0; i < parameters.length; i++) {
     parameters[i] = ObjectWritable.readObject(in, objectWritable, this.conf);
     parameterClasses[i] = objectWritable.getDeclaredClass();
   }
 }
Beispiel #11
0
 /** Get the blocks associated with the file */
 public Block[] getFile(UTF8 src) {
   waitForReady();
   synchronized (rootDir) {
     INode targetNode = rootDir.getNode(src.toString());
     if (targetNode == null) {
       return null;
     } else {
       return targetNode.blocks;
     }
   }
 }
Beispiel #12
0
 public void readFields(DataInput in) throws IOException {
   String className = UTF8.readString(in);
   declaredClass = PRIMITIVE_NAMES.get(className);
   if (declaredClass == null) {
     try {
       declaredClass = getConf().getClassByName(className);
     } catch (ClassNotFoundException e) {
       throw new RuntimeException(e.toString());
     }
   }
 }
 /** Test that decoding invalid UTF8 throws an appropriate error message. */
 @Test
 public void testInvalidUTF8() throws Exception {
   byte[] invalid =
       new byte[] {0x01, 0x02, (byte) 0xff, (byte) 0xff, 0x01, 0x02, 0x03, 0x04, 0x05};
   try {
     UTF8.fromBytes(invalid);
     fail("did not throw an exception");
   } catch (UTFDataFormatException utfde) {
     GenericTestUtils.assertExceptionContains("Invalid UTF8 at ffff01020304", utfde);
   }
 }
Beispiel #14
0
 boolean unprotectedAddFile(UTF8 name, Block blocks[]) {
   synchronized (rootDir) {
     if (blocks != null) {
       // Add file->block mapping
       for (int i = 0; i < blocks.length; i++) {
         activeBlocks.add(blocks[i]);
       }
     }
     return (rootDir.addNode(name.toString(), blocks) != null);
   }
 }
Beispiel #15
0
  /** Add the given filename to the fs. */
  public boolean addFile(UTF8 src, Block blocks[]) {
    waitForReady();

    // Always do an implicit mkdirs for parent directory tree
    mkdirs(DFSFile.getDFSParent(src.toString()));
    if (unprotectedAddFile(src, blocks)) {
      logEdit(OP_ADD, src, new ArrayWritable(Block.class, blocks));
      return true;
    } else {
      return false;
    }
  }
 /** Test that decoding invalid UTF8 due to truncation yields the correct exception type. */
 @Test
 public void testInvalidUTF8Truncated() throws Exception {
   // Truncated CAT FACE character -- this is a 4-byte sequence, but we
   // only have the first three bytes.
   byte[] truncated = new byte[] {(byte) 0xF0, (byte) 0x9F, (byte) 0x90};
   try {
     UTF8.fromBytes(truncated);
     fail("did not throw an exception");
   } catch (UTFDataFormatException utfde) {
     GenericTestUtils.assertExceptionContains("Truncated UTF8 at f09f90", utfde);
   }
 }
  @Test
  public void testGetBytes() throws Exception {
    for (int i = 0; i < 10000; i++) {

      // generate a random string
      String before = getTestString();

      // Check that the bytes are stored correctly in Modified-UTF8 format.
      // Note that the DataInput and DataOutput interfaces convert between
      // bytes and Strings using the Modified-UTF8 format.
      assertEquals(before, readModifiedUTF(UTF8.getBytes(before)));
    }
  }
 /** Test for a 5-byte UTF8 sequence, which is now considered illegal. */
 @Test
 public void test5ByteUtf8Sequence() throws Exception {
   byte[] invalid =
       new byte[] {
         0x01, 0x02, (byte) 0xf8, (byte) 0x88, (byte) 0x80, (byte) 0x80, (byte) 0x80, 0x04, 0x05
       };
   try {
     UTF8.fromBytes(invalid);
     fail("did not throw an exception");
   } catch (UTFDataFormatException utfde) {
     GenericTestUtils.assertExceptionContains("Invalid UTF8 at f88880808004", utfde);
   }
 }
  @Test
  public void testIO() throws Exception {
    DataOutputBuffer out = new DataOutputBuffer();
    DataInputBuffer in = new DataInputBuffer();

    for (int i = 0; i < 10000; i++) {
      // generate a random string
      String before = getTestString();

      // write it
      out.reset();
      UTF8.writeString(out, before);

      // test that it reads correctly
      in.reset(out.getData(), out.getLength());
      String after = UTF8.readString(in);
      assertEquals(before, after);

      // test that it reads correctly with DataInput
      in.reset(out.getData(), out.getLength());
      String after2 = in.readUTF();
      assertEquals(before, after2);
    }
  }
  /**
   * Test encoding and decoding of UTF8 outside the basic multilingual plane.
   *
   * <p>This is a regression test for HADOOP-9103.
   */
  @Test
  public void testNonBasicMultilingualPlane() throws Exception {
    // Test using the "CAT FACE" character (U+1F431)
    // See http://www.fileformat.info/info/unicode/char/1f431/index.htm
    String catFace = "\uD83D\uDC31";

    // This encodes to 4 bytes in UTF-8:
    byte[] encoded = catFace.getBytes("UTF-8");
    assertEquals(4, encoded.length);
    assertEquals("f09f90b1", StringUtils.byteToHexString(encoded));

    // Decode back to String using our own decoder
    String roundTrip = UTF8.fromBytes(encoded);
    assertEquals(catFace, roundTrip);
  }
Beispiel #21
0
 boolean unprotectedRenameTo(UTF8 src, UTF8 dst) {
   synchronized (rootDir) {
     INode removedNode = rootDir.getNode(src.toString());
     if (removedNode == null) {
       return false;
     }
     removedNode.removeNode();
     if (isDir(dst)) {
       dst = new UTF8(dst.toString() + "/" + new File(src.toString()).getName());
     }
     INode newNode = rootDir.addNode(dst.toString(), removedNode.blocks);
     if (newNode != null) {
       newNode.children = removedNode.children;
       for (Iterator it = newNode.children.values().iterator(); it.hasNext(); ) {
         INode child = (INode) it.next();
         child.parent = newNode;
       }
       return true;
     } else {
       rootDir.addNode(src.toString(), removedNode.blocks);
       return false;
     }
   }
 }
Beispiel #22
0
 Block[] unprotectedDelete(UTF8 src) {
   synchronized (rootDir) {
     INode targetNode = rootDir.getNode(src.toString());
     if (targetNode == null) {
       return null;
     } else {
       //
       // Remove the node from the namespace and GC all
       // the blocks underneath the node.
       //
       if (!targetNode.removeNode()) {
         return null;
       } else {
         Vector v = new Vector();
         targetNode.collectSubtreeBlocks(v);
         for (Iterator it = v.iterator(); it.hasNext(); ) {
           Block b = (Block) it.next();
           activeBlocks.remove(b);
         }
         return (Block[]) v.toArray(new Block[v.size()]);
       }
     }
   }
 }
Beispiel #23
0
  boolean savetextdata() throws IOException {
    boolean rc = false;
    // read html lines one by one and search for java script array of video URLs
    String sline = "";
    while (sline != null) {
      sline = this.textreader.readLine();
      try {
        if (this.iRecursionCount == 0 && sline.matches("(.*)\"url_encoded_fmt_stream_map\":(.*)")) {
          rc = true;
          HashMap<String, String> ssourcecodevideourls = new HashMap<String, String>();

          sline = sline.replaceFirst(".*\"url_encoded_fmt_stream_map\": \"", "");
          sline = sline.replaceFirst("\".*", "");
          sline = sline.replace("%25", "%");
          sline = sline.replace("\\u0026", "&");
          sline = sline.replace("\\", "");

          // by anonymous
          String[] ssourcecodeyturls = sline.split(",");
          debugoutput(
              "ssourcecodeuturls.length: ".concat(Integer.toString(ssourcecodeyturls.length)));
          String sResolutions =
              JFCMainClient.isgerman()
                  ? "gefundene Video URL für Auflösung: "
                  : "found video URL for resolution: ";

          for (String urlString : ssourcecodeyturls) {

            // assuming rtmpe is used for all resolutions, if found once - end download
            if (urlString.matches(".*conn=rtmpe.*")) {
              debugoutput("RTMPE found. cannot download this one!");
              output(
                  JFCMainClient.isgerman()
                      ? "Herunterladen des Videos wegen nicht unterstütztem Protokoll (RTMPE) leider nicht möglich!"
                      : "Unable to download video due to unsupported protocol (RTMPE). sry!");
              break;
            }
            String[] fmtUrlPair = urlString.split("url=http", 2);
            fmtUrlPair[1] = "url=http" + fmtUrlPair[1] + "&" + fmtUrlPair[0];
            // grep itag=xz out and use xy as hash key
            // 2013-02 itag now has up to 3 digits
            fmtUrlPair[0] =
                fmtUrlPair[1].substring(
                    fmtUrlPair[1].indexOf("itag=") + 5,
                    fmtUrlPair[1].indexOf("itag=")
                        + 5
                        + 1
                        + (fmtUrlPair[1].matches(".*itag=[0-9]{2}.*") ? 1 : 0)
                        + (fmtUrlPair[1].matches(".*itag=[0-9]{3}.*") ? 1 : 0));
            fmtUrlPair[1] = fmtUrlPair[1].replaceFirst("url=http%3A%2F%2F", "http://");
            fmtUrlPair[1] =
                fmtUrlPair[1]
                    .replaceAll("%3F", "?")
                    .replaceAll("%2F", "/")
                    .replaceAll("%3B", ";")
                    .replaceAll("%2C", ",")
                    .replaceAll("%3D", "=")
                    .replaceAll("%26", "&")
                    .replaceAll("%252C", "%2C")
                    .replaceAll("sig=", "signature=")
                    .replaceAll("&s=", "&signature=")
                    .replaceAll("\\?s=", "?signature=");

            // remove duplicated &itag=xy
            if (StringUtils.countMatches(fmtUrlPair[1], "itag=") == 2)
              fmtUrlPair[1] = fmtUrlPair[1].replaceFirst("itag=[0-9]{1,3}", "");

            try {
              ssourcecodevideourls.put(fmtUrlPair[0], fmtUrlPair[1]); // save that URL
              // debugoutput(String.format( "video url saved with key %s:
              // %s",fmtUrlPair[0],ssourcecodevideourls.get(fmtUrlPair[0]) ));
              sResolutions =
                  sResolutions.concat(
                      fmtUrlPair[0].equals("37")
                          ? "1080p mpeg, "
                          : // HD		type=video/mp4;+codecs="avc1.64001F,+mp4a.40.2"
                          fmtUrlPair[0].equals("22")
                              ? "720p mpeg, "
                              : // HD		type=video/mp4;+codecs="avc1.64001F,+mp4a.40.2"
                              fmtUrlPair[0].equals("84")
                                  ? "1080p 3d mpeg, "
                                  : // HD 3D	type=video/mp4;+codecs="avc1.64001F,+mp4a.40.2"
                                  fmtUrlPair[0].equals("35")
                                      ? "480p flv, "
                                      : // SD		type=video/x-flv
                                      fmtUrlPair[0].equals("18")
                                          ? "360p mpeg, "
                                          : // SD		type=video/mp4;+codecs="avc1.42001E,+mp4a.40.2"
                                          fmtUrlPair[0].equals("34")
                                              ? "360p flv, "
                                              : // SD		type=video/x-flv
                                              fmtUrlPair[0].equals("82")
                                                  ? "360p 3d mpeg, "
                                                  : // SD 3D
                                                  //	type=video/mp4;+codecs="avc1.42001E,+mp4a.40.2"
                                                  fmtUrlPair[0].equals("36")
                                                      ? "240p mpeg 3gpp, "
                                                      : // LD
                                                      //	type=video/3gpp;+codecs="mp4v.20.3,+mp4a.40.2"
                                                      fmtUrlPair[0].equals("17")
                                                          ? "114p mpeg 3gpp, "
                                                          : // LD
                                                          //	type=video/3gpp;+codecs="mp4v.20.3,+mp4a.40.2"
                                                          fmtUrlPair[0].equals("46")
                                                              ? "1080p webm, "
                                                              : // HD
                                                              //	type=video/webm;+codecs="vp8.0,+vorbis"&
                                                              fmtUrlPair[0].equals("45")
                                                                  ? "720p webm, "
                                                                  : // HD
                                                                  //	type=video/webm;+codecs="vp8.0,+vorbis"
                                                                  fmtUrlPair[0].equals("100")
                                                                      ? "1080p 3d webm, "
                                                                      : // HD 3D
                                                                      //	type=video/webm;+codecs="vp8.0,+vorbis"&
                                                                      fmtUrlPair[0].equals("44")
                                                                          ? "480p webm, "
                                                                          : // SD
                                                                          //	type=video/webm;+codecs="vp8.0,+vorbis"
                                                                          fmtUrlPair[0].equals("43")
                                                                              ? "360p webm, "
                                                                              : // SD
                                                                              //	type=video/webm;+codecs="vp8.0,+vorbis"
                                                                              fmtUrlPair[0].equals(
                                                                                      "102")
                                                                                  ? "360p 3d webm, "
                                                                                  : // SD 3D
                                                                                  //	type=video/webm;+codecs="vp8.0,+vorbis"&
                                                                                  fmtUrlPair[0]
                                                                                          .equals(
                                                                                              "5")
                                                                                      ? "240p flv, "
                                                                                      : // LD
                                                                                      //	type=video/x-flv
                                                                                      "unknown resolution! ("
                                                                                          .concat(
                                                                                              fmtUrlPair[
                                                                                                  0])
                                                                                          .concat(
                                                                                              ")"));
            } catch (java.lang.ArrayIndexOutOfBoundsException aioobe) {
            }
          } // for

          if (JFCMainClient.frame != null) output(sResolutions);
          debugoutput(sResolutions);

          int iindex;
          iindex = 0;
          this.vNextVideoURL.removeAllElements();

          debugoutput(
              "ssourcecodevideourls.length: "
                  .concat(Integer.toString(ssourcecodevideourls.size())));
          // figure out what resolution-button is pressed now and fill list with possible URLs
          switch (JFCMainClient.getIdlbuttonstate()) {
            case 4: // HD
              // try 1080p/720p in selected format first. if it's not available than the other
              // format will be used
              if (JFCMainClient.getBmpgbuttonstate())
                iindex = addMPEG_HD_Urls(iindex, ssourcecodevideourls);

              if (JFCMainClient.getBwebmbuttonstate())
                iindex = addWBEM_HD_Urls(iindex, ssourcecodevideourls);

              // there are no FLV HD URLs for now, so at least try mpg,wbem HD then
              iindex = addMPEG_HD_Urls(iindex, ssourcecodevideourls);
              iindex = addWBEM_HD_Urls(iindex, ssourcecodevideourls);

              // $FALL-THROUGH$
            case 2: // SD
              // try to download desired format first, if it's not available we take the other of
              // same res
              if (JFCMainClient.getBmpgbuttonstate())
                iindex = addMPEG_SD_Urls(iindex, ssourcecodevideourls);

              if (JFCMainClient.getBwebmbuttonstate())
                iindex = addWBEM_SD_Urls(iindex, ssourcecodevideourls);

              if (JFCMainClient.getBflvbuttonstate())
                iindex = addFLV_SD_Urls(iindex, ssourcecodevideourls);

              iindex = addMPEG_SD_Urls(iindex, ssourcecodevideourls);
              iindex = addWBEM_SD_Urls(iindex, ssourcecodevideourls);
              iindex = addFLV_SD_Urls(iindex, ssourcecodevideourls);

              // $FALL-THROUGH$
            case 1: // LD

              // TODO this.sFilenameResPart = "(LD)"; // adding LD to filename because HD-Videos are
              // almost already named HD (?)
              if (JFCMainClient.getBmpgbuttonstate())
                iindex = addMPEG_LD_Urls(iindex, ssourcecodevideourls);

              if (JFCMainClient.getBwebmbuttonstate()) {
                // there are no wbem LD URLs for now
              }

              if (JFCMainClient.getBflvbuttonstate())
                iindex = addFLV_LD_Urls(iindex, ssourcecodevideourls);

              // we must ensure all (16) possible URLs get added to the list so that the list of
              // URLs is never empty
              iindex = addMPEG_LD_Urls(iindex, ssourcecodevideourls);
              iindex = addFLV_LD_Urls(iindex, ssourcecodevideourls);

              break;
            default:
              // this.vNextVideoURL = null;
              this.sVideoURL = null;
              break;
          }

          // if the first 2 entries are null than there are no URLs for the selected resolution
          // strictly speaking this is only true for HD as there are only two URLs in contrast to
          // three of SD - in this case the output will not be shown but downloading should work
          // anyway
          if (this.vNextVideoURL.get(0).getsURL() == null
              && this.vNextVideoURL.get(1).getsURL() == null) {
            String smsg =
                JFCMainClient.isgerman()
                    ? "Video URL für ausgewählte Auflösung nicht gefunden! versuche geringere Auflösung..."
                    : "could not find video url for selected resolution! trying lower res...";
            output(smsg);
            debugoutput(smsg);
          }

          // remove null entries in list - we later try to download the first (index 0) and if it
          // fails the next one (at index 1) and so on
          for (int x = this.vNextVideoURL.size() - 1; x >= 0; x--) {
            if (this.vNextVideoURL.get(x).getsURL() == null) this.vNextVideoURL.remove(x);
          }

          try {
            this.sVideoURL = this.vNextVideoURL.get(0).getsURL();
            debugoutput(
                String.format(
                    "trying this one: %s %s %s",
                    this.vNextVideoURL.get(0).getsITAG(),
                    this.vNextVideoURL.get(0).getsQUALITY(),
                    this.vNextVideoURL.get(0).getsTYPE()));
          } catch (ArrayIndexOutOfBoundsException aioobe) {
          }

          this.setTitle(
              this.getTitle()
                  .concat(
                      JFCMainClient.isbSaveIDinFilename()
                          ? "." + this.vNextVideoURL.get(0).getsYTID()
                          : "")
                  .concat(
                      !this.vNextVideoURL.get(0).getsRESPART().equals("")
                          ? "." + this.vNextVideoURL.get(0).getsRESPART()
                          : ""));
        }

        if (this.iRecursionCount == 0 && sline.matches("(.*)<meta name=\"title\" content=(.*)")) {
          String stmp = sline.replaceFirst("(.*)<meta name=\"title\" content=", "").trim();
          // change html characters to their UTF8 counterpart
          stmp = UTF8.changeHTMLtoUTF8(stmp);
          stmp = stmp.replaceFirst("^\"", "").replaceFirst("\">$", "");
          this.setTitle(stmp); // complete file name without path
        }

      } catch (NullPointerException npe) {
      }
    } // while
    return rc;
  } // savetextdata()
Beispiel #24
0
 /** Create the given directory and all its parent dirs. */
 public boolean mkdirs(UTF8 src) {
   return mkdirs(src.toString());
 }
Beispiel #25
0
  /** Read a {@link Writable}, {@link String}, primitive type, or an array of the preceding. */
  @SuppressWarnings("unchecked")
  public static Object readObject(DataInput in, ObjectWritable objectWritable, Configuration conf)
      throws IOException {
    String className = UTF8.readString(in);
    Class<?> declaredClass = PRIMITIVE_NAMES.get(className);
    if (declaredClass == null) {
      declaredClass = loadClass(conf, className);
    }

    Object instance;

    if (declaredClass.isPrimitive()) { // primitive types

      if (declaredClass == Boolean.TYPE) { // boolean
        instance = Boolean.valueOf(in.readBoolean());
      } else if (declaredClass == Character.TYPE) { // char
        instance = Character.valueOf(in.readChar());
      } else if (declaredClass == Byte.TYPE) { // byte
        instance = Byte.valueOf(in.readByte());
      } else if (declaredClass == Short.TYPE) { // short
        instance = Short.valueOf(in.readShort());
      } else if (declaredClass == Integer.TYPE) { // int
        instance = Integer.valueOf(in.readInt());
      } else if (declaredClass == Long.TYPE) { // long
        instance = Long.valueOf(in.readLong());
      } else if (declaredClass == Float.TYPE) { // float
        instance = Float.valueOf(in.readFloat());
      } else if (declaredClass == Double.TYPE) { // double
        instance = Double.valueOf(in.readDouble());
      } else if (declaredClass == Void.TYPE) { // void
        instance = null;
      } else {
        throw new IllegalArgumentException("Not a primitive: " + declaredClass);
      }

    } else if (declaredClass.isArray()) { // array
      int length = in.readInt();
      instance = Array.newInstance(declaredClass.getComponentType(), length);
      for (int i = 0; i < length; i++) {
        Array.set(instance, i, readObject(in, conf));
      }

    } else if (declaredClass == String.class) { // String
      instance = UTF8.readString(in);
    } else if (declaredClass.isEnum()) { // enum
      instance = Enum.valueOf((Class<? extends Enum>) declaredClass, UTF8.readString(in));
    } else { // Writable
      Class instanceClass = null;
      String str = UTF8.readString(in);
      instanceClass = loadClass(conf, str);

      Writable writable = WritableFactories.newInstance(instanceClass, conf);
      writable.readFields(in);
      instance = writable;

      if (instanceClass == NullInstance.class) { // null
        declaredClass = ((NullInstance) instance).declaredClass;
        instance = null;
      }
    }

    if (objectWritable != null) { // store values
      objectWritable.declaredClass = declaredClass;
      objectWritable.instance = instance;
    }

    return instance;
  }
Beispiel #26
0
 public void write(DataOutput out) throws IOException {
   UTF8.writeString(out, declaredClass.getName());
 }
Beispiel #27
0
  /**
   * Load an edit log, and apply the changes to the in-memory structure
   *
   * <p>This is where we apply edits that we've been writing to disk all along.
   */
  int loadFSEdits(File edits) throws IOException {
    int numEdits = 0;

    if (edits.exists()) {
      DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(edits)));
      try {
        while (in.available() > 0) {
          byte opcode = in.readByte();
          numEdits++;
          switch (opcode) {
            case OP_ADD:
              {
                UTF8 name = new UTF8();
                name.readFields(in);
                ArrayWritable aw = new ArrayWritable(Block.class);
                aw.readFields(in);
                Writable writables[] = (Writable[]) aw.get();
                Block blocks[] = new Block[writables.length];
                System.arraycopy(writables, 0, blocks, 0, blocks.length);
                unprotectedAddFile(name, blocks);
                break;
              }
            case OP_RENAME:
              {
                UTF8 src = new UTF8();
                UTF8 dst = new UTF8();
                src.readFields(in);
                dst.readFields(in);
                unprotectedRenameTo(src, dst);
                break;
              }
            case OP_DELETE:
              {
                UTF8 src = new UTF8();
                src.readFields(in);
                unprotectedDelete(src);
                break;
              }
            case OP_MKDIR:
              {
                UTF8 src = new UTF8();
                src.readFields(in);
                unprotectedMkdir(src.toString());
                break;
              }
            default:
              {
                throw new IOException("Never seen opcode " + opcode);
              }
          }
        }
      } finally {
        in.close();
      }
    }
    return numEdits;
  }