Ejemplo n.º 1
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 private void externalizeMap(LinkedHashMap map, ObjectOutput out) throws IOException {
   int keyType = 0, valueType = 1, size;
   Iterator<Entry> it;
   Iterator cit;
   Entry e;
   Object value;
   if (map == null) {
     out.writeInt(0);
     out.flush();
     return;
   }
   size = map.keySet().size();
   if (map.keySet().iterator().next().getClass().equals(String.class)) {
     keyType = 1;
   }
   cit = map.values().iterator();
   value = cit.next();
   if (((ArrayList) value).get(0).getClass().equals(Commit.class)) {
     valueType = 0;
   } else if (((ArrayList) value).get(0).getClass().equals(PersonFrequency.class)) {
     valueType = 2;
   }
   out.writeInt(size);
   out.writeInt(keyType);
   out.writeInt(valueType);
   it = map.entrySet().iterator();
   while (it.hasNext()) {
     e = it.next();
     out.writeInt(((ArrayList) e.getValue()).size());
     cit = ((ArrayList) e.getValue()).iterator();
     while (cit.hasNext()) {
       value = cit.next();
       switch (valueType) {
         case 0:
           out.writeInt(Collections.binarySearch(allCommits, ((Commit) value)));
           break;
         case 1:
           out.writeInt(((BranchRef) value).index);
           break;
         default:
           out.writeInt(((PersonFrequency) value).index);
           out.writeInt(((PersonFrequency) value).freq);
           out.writeLong(((PersonFrequency) value).since);
           out.writeLong(((PersonFrequency) value).until);
       }
     }
     switch (keyType) {
       case 0:
         out.writeInt(Collections.binarySearch(allCommits, (Commit) e.getKey()));
         break;
       case 1:
         out.writeUTF(((String) e.getKey()));
     }
   }
   out.flush();
 }
  private void updatePackageBinaries(PackageItem item, PackageAssembler packageAssembler)
      throws DetailedSerializationException {
    try {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutput out = new DroolsObjectOutputStream(bout);
      out.writeObject(packageAssembler.getBinaryPackage());

      item.updateCompiledPackage(new ByteArrayInputStream(bout.toByteArray()));
      out.flush();
      out.close();

      item.updateBinaryUpToDate(true);

      RuleBase ruleBase =
          RuleBaseFactory.newRuleBase(new RuleBaseConfiguration(getClassLoaders(packageAssembler)));
      ruleBase.addPackage(packageAssembler.getBinaryPackage());

      rulesRepository.save();
    } catch (Exception e) {
      e.printStackTrace();
      log.error(
          "An error occurred building the package [" + item.getName() + "]: " + e.getMessage());
      throw new DetailedSerializationException(
          "An error occurred building the package.", e.getMessage());
    }
  }
 public void close() throws IOException {
   if (out != null) {
     // out _nicht_ schliessen, das macht die VM.
     out.flush();
     out = null;
   }
 }
  public static void serializeCCAVariantsRun(String directoryName) {

    // String fileDirPath =
    // "/Users/sameerkhurana10/Documents/serializedprojections/"
    // + directoryName;

    String fileDirPath =
        "/afs/inf.ed.ac.uk/group/project/vsm.restored/semanticprojectionserobjects/"
            + directoryName;

    File fileDir = new File(fileDirPath);
    if (!fileDir.exists()) {
      fileDir.mkdirs();
    }
    String fileName = fileDir.getAbsolutePath() + "/projectionInside.ser";
    String fileName1 = fileDir.getAbsolutePath() + "/projectionOutside.ser";

    try {
      ObjectOutput inside = new ObjectOutputStream(new FileOutputStream(fileName));
      ObjectOutput outside = new ObjectOutputStream(new FileOutputStream(fileName1));

      /*
       * Inside serialization
       */
      outside.writeObject(phiL);
      outside.flush();
      outside.close();

      /*
       * Outside serialization
       */
      inside.writeObject(phiR);
      inside.flush();
      inside.close();

      System.out.println("=======Serialized the CCA Variant Run=======");
    } catch (IOException ioe) {
      System.out.println(ioe.getMessage());
    }
  }
Ejemplo n.º 5
0
  private static void bigBlobCompile() throws DroolsParserException, IOException, Exception {
    StringBuilder buf = new StringBuilder();
    buf.append(getHeader());

    for (int i = 0; i < RULE_COUNT; i++) {
      String name = "x" + i;
      int status = i;

      String r = getTemplate1(name, status);
      buf.append(r);
    }

    /* love you */ long time = System.currentTimeMillis();

    DrlParser ps = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr pkg = ps.parse(new StringReader(buf.toString()));

    System.err.println("Time taken for parsing: " + (System.currentTimeMillis() - time));

    time = System.currentTimeMillis();
    PackageBuilder b = new PackageBuilder();
    b.addPackage(pkg);
    assertFalse(b.getErrors().toString(), b.hasErrors());

    System.err.println("Time taken for compiling: " + (System.currentTimeMillis() - time));
    time = System.currentTimeMillis();

    Package p = b.getPackage();
    RuleBase rb = RuleBaseFactory.newRuleBase();

    rb.addPackage(p);

    System.err.println("Time taken rete building: " + (System.currentTimeMillis() - time));

    File f = new File("foo.rulebase");
    if (f.exists()) f.delete();

    time = System.currentTimeMillis();
    ObjectOutput out = new DroolsObjectOutputStream(new FileOutputStream(f));
    out.writeObject(rb);
    out.flush();
    out.close();
    System.err.println("Time taken serializing rulebase: " + (System.currentTimeMillis() - time));

    time = System.currentTimeMillis();
    ObjectInputStream in = new ObjectInputStream(new FileInputStream(f));
    RuleBase rb_ = (RuleBase) in.readObject();
    System.err.println(
        "Time taken de-serializing rulebase: " + (System.currentTimeMillis() - time));
  }
Ejemplo n.º 6
0
  public static void flushAndCloseOutput(ObjectOutput o) {
    if (o == null) return;
    try {
      o.flush();
    } catch (Exception e) {

    }

    try {
      o.close();
    } catch (Exception e) {

    }
  }
Ejemplo n.º 7
0
  @Override
  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeUTF(name);
    out.writeLong(id);
    out.writeInt(allBranches.size());
    Iterator<BranchRef> itb = allBranches.iterator();
    while (itb.hasNext()) {
      itb.next().writeExternal(out);
    }
    out.writeInt(allCommits.size());
    Iterator<Commit> itc = allCommits.iterator();
    while (itc.hasNext()) {
      itc.next().writeExternal(out);
    }
    out.writeInt(allAuthors.size());
    Iterator<Person> itp = allAuthors.iterator();
    while (itp.hasNext()) {
      itp.next().writeExternal(out);
    }

    externalizeMap(branches, out);
    externalizeMap(comInB, out);

    externalizeMap(comOnlyInB, out);
    externalizeMap(comInF, out);
    externalizeMap(comOnlyInF, out);
    externalizeMap(comNotInF, out);
    externalizeMap(authOfComInB, out);
    externalizeMap(authOfComOnlyInB, out);
    externalizeMap(authOfComInF, out);
    externalizeMap(authOfComOnlyInF, out);
    externalizeMap(authOfComNotInF, out);

    if (metaGraph == null) out.writeInt(0);
    else metaGraph.writeExternal(out);

    out.flush();
  }
Ejemplo n.º 8
0
 public static byte[] objectToBytes(Object obj) {
   byte[] bytes = getNull();
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutput oo = null;
   try {
     oo = new ObjectOutputStream(baos);
     oo.writeObject(obj);
     oo.flush();
     bytes = baos.toByteArray();
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     try {
       if (oo != null) {
         oo.close();
       }
       baos.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   return bytes;
 }
Ejemplo n.º 9
0
  public void releaseOutputStream() throws IOException {
    if (vec != null) {
      oout = conn.getObjectOutputStream();

      for (int i = 0; i < vec.size(); i += 2) {
        boolean primitive = ((Boolean) vec.elementAt(i)).booleanValue();
        Object data = vec.elementAt(i + 1);

        // No type, this is
        if (!primitive) oout.writeObject(data);
        else {
          if (data instanceof Boolean) oout.writeBoolean(((Boolean) data).booleanValue());
          else if (data instanceof Character) oout.writeChar(((Character) data).charValue());
          else if (data instanceof Byte) oout.writeByte(((Byte) data).byteValue());
          else if (data instanceof Short) oout.writeShort(((Short) data).shortValue());
          else if (data instanceof Integer) oout.writeInt(((Integer) data).intValue());
          else if (data instanceof Long) oout.writeLong(((Long) data).longValue());
        }
      }
      vec = null;
    }
    if (oout != null) oout.flush();
  }
 public void flush() throws IOException {
   out.flush();
 }