コード例 #1
0
 /** 这里我做了更改,当手动放入缓存文件后,需要对缓存文件做一次记录 */
 private void refreshJournal() {
   try {
     File[] entryFiles = directory.listFiles();
     for (File entryFile : entryFiles) {
       if (entryFile.getName().length() < 32) continue;
       String key = entryFile.getName().replace(".0", "");
       Entry entry = lruEntries.get(key);
       // 这个文件不存在journal文件中
       if (entry == null) {
         entry = new Entry(key);
         entry.readable = true;
         entry.setLengths(new String[] {entryFile.length() + ""});
         lruEntries.put(key, entry);
         if (journalWriter == null)
           journalWriter = new BufferedWriter(new FileWriter(journalFile, true), IO_BUFFER_SIZE);
         journalWriter.append(DIRTY + ' ' + entry.key + '\n');
         journalWriter.append(CLEAN + ' ' + key + entry.getLengths() + '\n');
       }
     }
     //			readJournal();
     //			trimToSize();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
 public void testReuseVersion() throws Exception {
   BlobVersion trx1 = store.newVersion("urn:test:trx1");
   Writer file1 = trx1.open("urn:test:file1").openWriter();
   file1.append("blob store test");
   file1.close();
   trx1.commit();
   BlobVersion trx2 = store.newVersion("urn:test:trx2");
   file1 = trx2.open("urn:test:file1").openWriter();
   file1.append("blob store test");
   file1.close();
   trx2.commit();
   Writer file2 = trx2.open("urn:test:file2").openWriter();
   file2.append("blob store test");
   file2.close();
   trx2.commit();
   trx2 = store.newVersion("urn:test:trx2");
   file2 = trx2.open("urn:test:file2").openWriter();
   file2.append("blob store test");
   file2.close();
   trx2.commit();
   BlobVersion trx3 = store.newVersion("urn:test:trx3");
   CharSequence str1 = trx3.open("urn:test:file1").getCharContent(true);
   assertEquals("blob store test", str1.toString());
   CharSequence str2 = trx3.open("urn:test:file2").getCharContent(true);
   assertEquals("blob store test", str2.toString());
 }
コード例 #3
0
  @Override
  public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
    try (ZipInputStream zis = new ZipInputStream(src.getStream())) {
      ZipEntry entry;
      while ((entry = zis.getNextEntry()) != null) {
        String ename = entry.getName();

        if (xrefOut != null) {
          xrefOut.append("<br/><b>");
          Util.htmlize(ename, xrefOut);
          xrefOut.append("</b>");
        }

        doc.add(new TextField("full", ename, Store.NO));
        IFileAnalyzerFactory fac = AnalyzerGuru.find(ename);
        if (fac instanceof JavaClassAnalyzerFactory) {
          if (xrefOut != null) {
            xrefOut.append("<pre>");
          }

          JavaClassAnalyzer jca = (JavaClassAnalyzer) fac.getAnalyzer();
          jca.analyze(doc, new BufferedInputStream(zis), xrefOut);

          if (xrefOut != null) {
            xrefOut.append("</pre>");
          }
        }
      }
    }
  }
コード例 #4
0
ファイル: JsonWriter.java プロジェクト: sangmin/jclouds
  /**
   * Inserts any necessary separators and whitespace before a literal value, inline array, or inline
   * object. Also adjusts the stack to expect either a closing bracket or another element.
   *
   * @param root true if the value is a new array or object, the two values permitted as top-level
   *     elements.
   */
  private void beforeValue(boolean root) throws IOException {
    switch (peek()) {
      case EMPTY_DOCUMENT: // first in document
        if (!lenient && !root) {
          throw new IllegalStateException("JSON must start with an array or an object.");
        }
        replaceTop(JsonScope.NONEMPTY_DOCUMENT);
        break;

      case EMPTY_ARRAY: // first in array
        replaceTop(JsonScope.NONEMPTY_ARRAY);
        newline();
        break;

      case NONEMPTY_ARRAY: // another in array
        out.append(',');
        newline();
        break;

      case DANGLING_NAME: // value for name
        out.append(separator);
        replaceTop(JsonScope.NONEMPTY_OBJECT);
        break;

      case NONEMPTY_DOCUMENT:
        throw new IllegalStateException("JSON must have only one top-level value.");

      default:
        throw new IllegalStateException("Nesting problem: " + stack);
    }
  }
コード例 #5
0
 @Override
 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
     throws Exception {
   HttpSession session = request.getSession();
   Object typeAttr = session.getAttribute(User.TYPE);
   if (typeAttr == null) {
     Logger.getLogger(AuthorityInterceptor.class)
         .warn("errorCode:" + ErrorCode.ILLEGAL_ACCESS_ERROR + " from:" + getIpAddress(request));
     response.setContentType("application/json;charset=UTF-8");
     Writer writer = response.getWriter();
     writer.append(jsonUtil.setFailRes(ErrorCode.ILLEGAL_ACCESS_ERROR).toJson());
     writer.flush();
     writer.close();
     return false;
   }
   int userType = (int) typeAttr;
   if (userType != type) {
     // 指定类型的url,只能有指定类型的用访问
     Logger.getLogger(AuthorityInterceptor.class)
         .warn(
             "errorCode:" + ErrorCode.PERMISSION_DENIED_ERROR + " from:" + getIpAddress(request));
     response.setContentType("application/json;charset=UTF-8");
     Writer writer = response.getWriter();
     writer.append(jsonUtil.setFailRes(ErrorCode.PERMISSION_DENIED_ERROR).toJson());
     writer.flush();
     writer.close();
     return false;
   }
   return true;
 }
コード例 #6
0
ファイル: Schemas.java プロジェクト: eimmermann/service-proxy
 private void assembleXSD(Writer w, Model m, MainInfo main)
     throws IOException, ProcessingException {
   String namespace = main.getAnnotation().targetNamespace();
   w.append(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
           + "<xsd:schema xmlns=\""
           + namespace
           + "\"\r\n"
           + "	xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:beans=\"http://www.springframework.org/schema/beans\"\r\n"
           + "	targetNamespace=\""
           + namespace
           + "\"\r\n"
           + "	elementFormDefault=\"qualified\" attributeFormDefault=\"unqualified\">\r\n"
           + "\r\n"
           + "<!-- Automatically generated by "
           + Schemas.class.getName()
           + ". -->\r\n"
           + "\r\n"
           + "<xsd:import namespace=\"http://www.springframework.org/schema/beans\" schemaLocation=\"http://www.springframework.org/schema/beans/spring-beans-3.1.xsd\" />\r\n"
           + "\r\n"
           + "<xsd:simpleType name=\"spel_number\">\r\n"
           + "    <xsd:restriction base=\"xsd:string\">\r\n"
           + "        <xsd:pattern value=\"-?[0-9]+|\\#\\{.*\\}\"></xsd:pattern>\r\n"
           + "    </xsd:restriction>\r\n"
           + "</xsd:simpleType>\r\n"
           + "\r\n"
           + "<xsd:simpleType name=\"spel_boolean\">\r\n"
           + "    <xsd:restriction base=\"xsd:string\">\r\n"
           + "        <xsd:pattern value=\"[01]|true|false|\\#\\{.*\\}\"></xsd:pattern>\r\n"
           + "    </xsd:restriction>\r\n"
           + "</xsd:simpleType>\r\n\r\n");
   assembleDeclarations(w, m, main);
   w.append("</xsd:schema>");
 }
コード例 #7
0
ファイル: HtmlRender.java プロジェクト: zhangxian97/Shane
 public HtmlRender putTextNode(String text, String htmlId, String styleClass) throws IOException {
   indent();
   writer.append("<span");
   if (htmlId != null) writer.append(" id=\"").append(htmlId).append("\"");
   if (styleClass != null) writer.append(" class=\"").append(styleClass).append("\"");
   writer.append(">").append(text).append("</span>");
   return this;
 }
コード例 #8
0
 public void writeDocumented(Writer writer, Object conf) throws IOException {
   // Write configuration description
   writeComments(writer, Descriptions.of(conf));
   writer.append(DOCUMENT_START);
   // Write only one configuration, but don't create a new list for that as SnakeYAML is doing that
   snakeYAML.getYaml().dumpAll(Iterators.singletonIterator(conf), writer);
   writer.append(newLine);
 }
コード例 #9
0
ファイル: Control.java プロジェクト: MZDN/k3po
  private void writeCommand(DisposeCommand dispose) throws IOException, CharacterCodingException {
    OutputStream bytesOut = connection.getOutputStream();
    CharsetEncoder encoder = UTF_8.newEncoder();
    Writer textOut = new OutputStreamWriter(bytesOut, encoder);

    textOut.append("DISPOSE\n");
    textOut.append("\n");
    textOut.flush();
  }
コード例 #10
0
  /** @see org.jpublish.ErrorHandler#handleError(JPublishError) */
  public boolean handleError(Throwable error, WebPageRequest context) {
    if (context.getResponse() != null
        && context.getResponse().getContentType() != null
        && !context.getResponse().getContentType().contains("json")) {
      return false;
    }

    OpenEditException exception = null;
    if (context != null) {
      try {
        if (!(error instanceof OpenEditException)) {
          exception = new OpenEditException(error); // we need the toStacktrace method
        } else {
          exception = (OpenEditException) error;
        }
        if (!context.hasRedirected() && context.getResponse() != null) {
          try {
            context.getResponse().setStatus(500);
          } catch (Exception ex) {
            // ignored
            log.debug("Ignored:" + ex);
          }
        }
        error.printStackTrace();
        String pathWithError = exception.getPathWithError();
        if (pathWithError == null) {
          pathWithError = context.getPage().getPath();
          exception.setPathWithError(pathWithError);
        }
        context.putPageValue("editPath", exception.getPathWithError());
        context.putPageValue(
            "oe-exception", exception); // must be a top level thing since we create a new context
        PageStreamer pages = (PageStreamer) context.getPageValue(PageRequestKeys.PAGES);

        Writer out = context.getWriter();
        out.append("{ \"reponse\": {\n");
        out.append(" \"status\":\"error\",");
        out.append("{ \"path\":\"" + pathWithError + "\",");
        out.append("{ \"details\":\"" + error + "\"");
        out.append("\n}");
        // error.printStackTrace( new PrintWriter( writer ) );
        out.flush();
      } catch (Exception ex) {
        // Do not throw an error here is it will be infinite
        log.error(ex);
        ex.printStackTrace();
        try {
          context.getWriter().write("Check error logs: " + ex);
          // throw new OpenEditRuntimeException(ex);
        } catch (Throwable ex1) {
          log.error(ex1);
        }
      }
      return true;
    }
    return false;
  }
コード例 #11
0
 private void appendRuleParameters(ActiveRule activeRule, Writer writer) throws IOException {
   if (activeRule.getActiveRuleParams() != null && !activeRule.getActiveRuleParams().isEmpty()) {
     writer.append("<parameters>");
     for (ActiveRuleParam activeRuleParam : activeRule.getActiveRuleParams()) {
       appendRuleParameter(writer, activeRuleParam);
     }
     writer.append("</parameters>");
   }
 }
コード例 #12
0
ファイル: HtmlRender.java プロジェクト: zhangxian97/Shane
 public HtmlRender putInputNode(String type, String... kvpairs) throws IOException {
   indent();
   writer.append("<input type=\"").append(type).append("\"");
   for (int i = 0; i < kvpairs.length; i += 2) {
     writer.append(" ").append(kvpairs[i]).append("=\"").append(kvpairs[i + 1]).append("\"");
   }
   writer.append("/>");
   return this;
 }
コード例 #13
0
 private void appendRules(RulesProfile profile, Writer writer) throws IOException {
   if (!profile.getActiveRules().isEmpty()) {
     writer.append("<rules>");
     for (ActiveRule activeRule : profile.getActiveRules()) {
       appendRule(activeRule, writer);
     }
     writer.append("</rules>");
   }
 }
コード例 #14
0
 private void appendAlerts(RulesProfile profile, Writer writer) throws IOException {
   if (!profile.getAlerts().isEmpty()) {
     writer.append("<alerts>");
     for (Alert alert : profile.getAlerts()) {
       appendAlert(alert, writer);
     }
     writer.append("</alerts>");
   }
 }
コード例 #15
0
  public static void traceState(
      ModulesRegistry registry, String state, long bundleId, String bundleName, Loader loader) {
    File out = new File(getLocation(), state + "-" + bundleId + ".log");
    Writer w = null;
    try {
      w = new FileWriter(out);
      w.append("\n");
      w.append("Module [" + bundleId + "] " + state + " " + bundleName + "\n");
      String prefix = "-";
      StackTraceElement[] stack = Thread.currentThread().getStackTrace();

      w.append("\n");
      w.append("-----------------------------------\n");
      w.append("Inhabitants / stack combination\n");
      w.append("-----------------------------------\n");

      String currentBundleName = bundleName;

      for (int i = 0; i < stack.length; i++) {
        {
          // now let's find out the first non hk2 class asking for this...
          int j = i + 1;
          for (; j < stack.length; j++) {
            StackTraceElement caller = stack[j];
            if (!caller.getClassName().contains("hk2")) {
              break;
            }
          }
        }
      }
      w.append("\n");

      w.append("---------------------------\n");
      w.append("Complete thread stack Trace\n");
      w.append("---------------------------\n");

      for (StackTraceElement element : stack) {
        w.append(element.toString() + "\n");
      }

    } catch (IOException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } finally {
      if (w != null) {
        try {
          w.close();
        } catch (IOException e) {
          e
              .printStackTrace(); // To change body of catch statement use File | Settings | File
                                  // Templates.
        }
      }
    }
  }
コード例 #16
0
 private void appendHeader(RulesProfile profile, Writer writer) throws IOException {
   writer.append(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
           + "<!-- Generated by Sonar -->"
           + "<profile><name>");
   StringEscapeUtils.escapeXml(writer, profile.getName());
   writer.append("</name><language>");
   StringEscapeUtils.escapeXml(writer, profile.getLanguage());
   writer.append("</language>");
 }
コード例 #17
0
 void writePropertyValues(int indentLevel, Writer writer) throws IOException {
   Set s = (Set) getValue();
   indent(indentLevel, writer);
   writer.append("<set>"); // $NON-NLS-1$
   newLine(writer);
   for (Iterator i = s.iterator(); i.hasNext(); )
     writePropertyValue(indentLevel + 1, i.next(), writer);
   indent(indentLevel, writer);
   writer.append("</set>"); // $NON-NLS-1$
 }
コード例 #18
0
 void writePropertyValues(int indentLevel, Writer writer) throws IOException {
   Object[] a = (Object[]) getValue();
   indent(indentLevel, writer);
   writer.append("<array>"); // $NON-NLS-1$
   newLine(writer);
   for (int i = 0; i < a.length; i++) writePropertyValue(indentLevel + 1, a[i], writer);
   indent(indentLevel, writer);
   writer.append("</array>"); // $NON-NLS-1$
   newLine(writer);
 }
コード例 #19
0
 public void testEraseMultiVersionSingleBlob() throws Exception {
   Writer file = store.open("urn:test:file").openWriter();
   file.append("blob store test1");
   file.close();
   file = store.open("urn:test:file").openWriter();
   file.append("blob store test2");
   file.close();
   store.erase();
   assertEmpty(dir);
 }
コード例 #20
0
 private void writeListNode(Node node, boolean writeSeparator) throws IOException {
   String label = node.getNodeData().getLabel();
   if (label == null) {
     label = node.getNodeData().getId();
   }
   writer.append(label);
   if (writeSeparator) {
     writer.append(SEPARATOR);
   }
 }
コード例 #21
0
ファイル: Control.java プロジェクト: MZDN/k3po
  private void writeCommand(AwaitCommand await) throws IOException, CharacterCodingException {
    OutputStream bytesOut = connection.getOutputStream();
    CharsetEncoder encoder = UTF_8.newEncoder();
    Writer textOut = new OutputStreamWriter(bytesOut, encoder);

    textOut.append("AWAIT\n");
    textOut.append(format("barrier:%s\n", await.getBarrier()));
    textOut.append("\n");
    textOut.flush();
  }
コード例 #22
0
ファイル: Control.java プロジェクト: MZDN/k3po
  private void writeCommand(StartCommand start) throws Exception {

    OutputStream bytesOut = connection.getOutputStream();
    CharsetEncoder encoder = UTF_8.newEncoder();
    Writer textOut = new OutputStreamWriter(bytesOut, encoder);

    textOut.append("START\n");
    textOut.append("\n");
    textOut.flush();
  }
コード例 #23
0
 private void writeSiteInfo(Writer writer, String virtualWikiName)
     throws DataAccessException, IOException {
   VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName);
   writer.append("\n<siteinfo>");
   String sitename = virtualWiki.getSiteName();
   writer.append('\n');
   XMLUtil.buildTag(writer, "sitename", sitename, true);
   String base = this.retrieveBaseUrl();
   writer.append('\n');
   XMLUtil.buildTag(writer, "base", base, true);
   String generator = "JAMWiki " + WikiVersion.CURRENT_WIKI_VERSION;
   writer.append('\n');
   XMLUtil.buildTag(writer, "generator", generator, true);
   /*
   Cannot have two titles differing only by case of first letter.  Default behavior through 1.5, $wgCapitalLinks = true
   	<enumeration value="first-letter" />
   Complete title is case-sensitive. Behavior when $wgCapitalLinks = false
   	<enumeration value="case-sensitive" />
   Cannot have two titles differing only by case. Not yet implemented as of MediaWiki 1.5
   	<enumeration value="case-insensitive" />
   */
   writer.append('\n');
   XMLUtil.buildTag(writer, "case", "case-sensitive", true);
   writer.append("\n<namespaces>");
   Map<String, String> attributes = new HashMap<String, String>();
   List<Namespace> namespaces = WikiBase.getDataHandler().lookupNamespaces();
   for (Namespace namespace : namespaces) {
     attributes.put("key", Integer.toString(namespace.getId()));
     writer.append('\n');
     XMLUtil.buildTag(writer, "namespace", namespace.getLabel(virtualWikiName), attributes, true);
   }
   writer.append("\n</namespaces>");
   writer.append("\n</siteinfo>");
 }
コード例 #24
0
ファイル: JsonRenderImpl.java プロジェクト: zms1207/nutz
 private void coll2Json(Collection iterable) throws IOException {
   writer.append('[');
   for (Iterator<?> it = iterable.iterator(); it.hasNext(); ) {
     render(it.next());
     if (it.hasNext()) {
       appendPairEnd();
       writer.append(' ');
     } else break;
   }
   writer.append(']');
 }
コード例 #25
0
 void writeXml(int indentLevel, Writer writer) throws IOException {
   indent(indentLevel, writer);
   writer.append("<xml>"); // $NON-NLS-1$
   newLine(writer);
   indent(indentLevel + 1, writer);
   writer.append((String) getValue());
   newLine(writer);
   indent(indentLevel, writer);
   writer.append("</xml>"); // $NON-NLS-1$
   newLine(writer);
 }
コード例 #26
0
 public void testConcurrency() throws Exception {
   Writer test1 = store.open("urn:test:file").openWriter();
   test1.append("test1");
   test1.close();
   Writer test2 = store.open("urn:test:file").openWriter();
   test2.append("test2");
   test2.flush();
   assertEquals("test1", store.open("urn:test:file").getCharContent(true).toString());
   test2.close();
   assertEquals("test2", store.open("urn:test:file").getCharContent(true).toString());
 }
コード例 #27
0
ファイル: OJSONWriter.java プロジェクト: joelgit2006/orientdb
  public OJSONWriter writeValue(final int iIdentLevel, final boolean iNewLine, final Object iValue)
      throws IOException {
    if (!firstAttribute) out.append(",");

    format(iIdentLevel, iNewLine);

    out.append(writeValue(iValue, format));

    firstAttribute = false;
    return this;
  }
コード例 #28
0
 public void writeProperty(int indentLevel, Writer writer) throws IOException {
   indent(indentLevel, writer);
   writer
       .append("<property name=\"")
       .append(getName())
       .append("\">"); // $NON-NLS-1$ //$NON-NLS-2$
   newLine(writer);
   writeXml(indentLevel + 1, writer);
   writer.append("</property>"); // $NON-NLS-1$
   newLine(writer);
 }
コード例 #29
0
ファイル: CodedBatch.java プロジェクト: jnorthrup/raccoon
  public void toString(Writer ioWriter) throws IOException {
    ioWriter.append("{");

    for (int i = 0; i < _size && i < CodedBatch._MAX_WRITE_SIZE; i++)
      ioWriter.append((i == 0 ? "" : ",") + BytesUtil.hex(_bm.getByte(i)));

    int remaining = _size - CodedBatch._MAX_WRITE_SIZE;
    if (remaining > 0) ioWriter.append(",...(" + remaining + ")");

    ioWriter.append("}");
  }
コード例 #30
0
 void writePropertyValues(int indentLevel, Writer writer) throws IOException {
   List l = (List) getValue();
   indent(indentLevel, writer);
   writer.append("<list>"); // $NON-NLS-1$
   newLine(writer);
   for (Iterator i = l.iterator(); i.hasNext(); )
     writePropertyValue(indentLevel + 1, i.next(), writer);
   indent(indentLevel, writer);
   writer.append("</list>"); // $NON-NLS-1$
   newLine(writer);
 }