javax.xml.bind.JAXB.marshal()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中javax.xml.bind.JAXB.marshal()方法的一些代码示例,展示了JAXB.marshal()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JAXB.marshal()方法的具体详情如下:
包路径:javax.xml.bind.JAXB
类名称:JAXB
方法名:marshal

JAXB.marshal介绍

[英]Writes a Java object tree to XML and store it to the specified location.
[中]将Java对象树写入XML并将其存储到指定位置。

代码示例

代码示例来源:origin: igniterealtime/Openfire

/**
 * Authenticates a user with crowd. If authentication failed, raises a <code>RemoteException</code>
 * @param username
 * @param password
 * @throws RemoteException
 */
public void authenticate(String username, String password) throws RemoteException {
  username = JID.unescapeNode(username);
  LOG.debug("authenticate '" + String.valueOf(username) + "'");
  final AuthenticatePost authenticatePost = new AuthenticatePost();
  authenticatePost.value = password;
  final StringWriter writer = new StringWriter();
  JAXB.marshal(authenticatePost, writer);
  final HttpUriRequest postRequest = RequestBuilder.post(crowdServer.resolve("authentication?username=" + urlEncode(username)))
    .setConfig(requestConfig)
    .setEntity(new StringEntity(writer.toString(), StandardCharsets.UTF_8))
    .setHeader(HEADER_CONTENT_TYPE_APPLICATION_XML)
    .build();
  try(final CloseableHttpResponse response = client.execute(postRequest, clientContext)) {
    if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
      handleHTTPError(response);
    }
    
  } catch (IOException ioe) {
    handleError(ioe);
  }
  
  LOG.info("authenticated user:" + username);
}

代码示例来源:origin: org.aktin/broker-client

@Override
  public void write(OutputStream dest) throws IOException {
    JAXB.marshal(jaxbObject, dest);
  }
});

代码示例来源:origin: org.apache.openejb/javaee-api

public static void marshal(Object object, String str) {
  if (str == null) {
    throw new IllegalStateException("No string destination is given");
  }
  try {
    marshal(object, new URI(str));
  } catch (URISyntaxException e) {
    marshal(object, new File(str));
  }
}

代码示例来源:origin: org.apache.openejb/javaee-api

public static void marshal(Object object, File file) {
  if (file == null) {
    throw new IllegalStateException("No file is given");
  }
  marshal(object, new StreamResult(file));
}

代码示例来源:origin: org.apache.openejb/javaee-api

public static void marshal(Object object, Writer writer) {
  if (writer == null) {
    throw new IllegalStateException("No writer is given");
  }
  marshal(object, new StreamResult(writer));
}

代码示例来源:origin: theotherp/nzbhydra2

public String toXmlString() {
  try (StringWriter writer = new StringWriter()) {
    JAXB.marshal(this, writer);
    return writer.toString();
  } catch (IOException e) {
    return null;
  }
}

代码示例来源:origin: harikrishnan83/rapa

public String serialize(Resource resource) {
  OutputStream outputStream = new ByteArrayOutputStream();
  JAXB.marshal(resource, outputStream);
  return outputStream.toString();
}

代码示例来源:origin: org.apache.geronimo.specs/geronimo-jaxb_2.1_spec

public static void marshal(Object object, OutputStream os) {
  if (os == null) {
    throw new IllegalStateException("No output stream is given");
  }
  marshal(object, new StreamResult(os));
}

代码示例来源:origin: org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.1

public static void marshal(Object object, File file) {
  if (file == null) {
    throw new IllegalStateException("No file is given");
  }
  marshal(object, new StreamResult(file));
}

代码示例来源:origin: org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.1

public static void marshal(Object object, OutputStream os) {
  if (os == null) {
    throw new IllegalStateException("No output stream is given");
  }
  marshal(object, new StreamResult(os));
}

代码示例来源:origin: org.apache.juddi/juddi-client

/**
 * Serializes a JAXB object and prints to stdout
 *
 * @param obj
 * @return serialized text
 */
public static String JAXB_ToString(Object obj) {
    StringWriter sw = new StringWriter();
    JAXB.marshal(obj, sw);
    return (sw.toString());
}

代码示例来源:origin: org.apache.juddi/juddi-client

/**
 * Serializes a JAXB object and prints to stdout
 *
 * @param obj
 */
public static void JAXB_ToStdOut(Object obj) {
    StringWriter sw = new StringWriter();
    JAXB.marshal(obj, sw);
    System.out.println(sw.toString());
}

代码示例来源:origin: org.perfrepo/perfrepo-client

private void setPostEntity(HttpPost req, Object obj) {
 ByteArrayOutputStream bos = new ByteArrayOutputStream();
 JAXB.marshal(obj, bos);
 req.setEntity(new ByteArrayEntity(bos.toByteArray()));
}

代码示例来源:origin: org.apache.juddi/juddi-core

private static synchronized void LogRequest(Object request) {
      if (isLogRequestPayloads())
      try {
         File f = new File(System.currentTimeMillis()+".xml");
         FileOutputStream fos = new FileOutputStream(f);
         JAXB.marshal(request, fos);
         fos.close();
         f = null;
     } catch (Exception ex) {
         logger.warn("Unable to log request payload", ex);
     }
  }

代码示例来源:origin: com.davidbracewell/mango

@Override
public void serialize(@NonNull Object o, @NonNull Resource resource) throws Exception {
 try (OutputStream outputStream = resource.outputStream()) {
   JAXB.marshal(o, outputStream);
 }
}

代码示例来源:origin: org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.1

public static void marshal(Object object, URI uri) {
  if (uri == null) {
    throw new IllegalStateException("No uri is given");
  }
  try {
    marshal(object, uri.toURL());
  } catch (IOException e) {
    throw new DataBindingException(e);
  }
}

代码示例来源:origin: org.parallelj/parallelj-jmx

Process newProcessor(ProgramTypeProxy programTypeProxy, Object context) {
  StringWriter writer = new StringWriter();
  JAXB.marshal(context, writer);
  return this.processes.parseInstance(this.management.newProcess(programTypeProxy.getId(), writer.toString()));
}

代码示例来源:origin: octo-online/reactive-audit

@Test(expected = FileReactiveAuditException.class)
public void marshal_URL()
    throws MalformedURLException
{
  TestTools.strict.commit();
  JAXB.marshal(null, IOTestTools.getTempFile().toURI().toURL());
}

代码示例来源:origin: octo-online/reactive-audit

@Test(expected = FileReactiveAuditException.class)
public void marshal_File()
{
  TestTools.strict.commit();
  JAXB.marshal(null, IOTestTools.getTempFile());
}

代码示例来源:origin: octo-online/reactive-audit

@Test(expected = FileReactiveAuditException.class)
public void marshal_Writer()
{
  TestTools.strict.commit();
  JAXB.marshal(null, IOTestTools.getTempFileWriter());
}

相关文章