当前位置: 首页>>代码示例>>Java>>正文


Java OutputStream.write方法代码示例

本文整理汇总了Java中java.io.OutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java OutputStream.write方法的具体用法?Java OutputStream.write怎么用?Java OutputStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.OutputStream的用法示例。


在下文中一共展示了OutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeToFile

import java.io.OutputStream; //导入方法依赖的package包/类
private static void writeToFile(InputStream in, File file) {
    try {
        OutputStream out = new FileOutputStream(file);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        out.close();
        in.close();


    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:17,代码来源:EasyImageFiles.java

示例2: encode

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * encode the input data producing a Hex output stream.
 *
 * @return the number of bytes produced.
 */
public int encode(
    byte[]                data,
    int                    off,
    int                    length,
    OutputStream    out) 
    throws IOException
{        
    for (int i = off; i < (off + length); i++)
    {
        int    v = data[i] & 0xff;

        out.write(encodingTable[(v >>> 4)]);
        out.write(encodingTable[v & 0xf]);
    }

    return length * 2;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:23,代码来源:HexEncoder.java

示例3: redirectedPostStripsRequestBodyHeaders

import java.io.OutputStream; //导入方法依赖的package包/类
@Test public void redirectedPostStripsRequestBodyHeaders() throws Exception {
  server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP)
      .addHeader("Location: /page2"));
  server.enqueue(new MockResponse().setBody("Page 2"));

  connection = urlFactory.open(server.url("/page1").url());
  connection.setDoOutput(true);
  connection.addRequestProperty("Content-Length", "4");
  connection.addRequestProperty("Content-Type", "text/plain; charset=utf-8");
  connection.addRequestProperty("Transfer-Encoding", "identity");
  OutputStream outputStream = connection.getOutputStream();
  outputStream.write("ABCD".getBytes("UTF-8"));
  outputStream.close();
  assertEquals("Page 2", readAscii(connection.getInputStream(), Integer.MAX_VALUE));

  assertEquals("POST /page1 HTTP/1.1", server.takeRequest().getRequestLine());

  RecordedRequest page2 = server.takeRequest();
  assertEquals("GET /page2 HTTP/1.1", page2.getRequestLine());
  assertNull(page2.getHeader("Content-Length"));
  assertNull(page2.getHeader("Content-Type"));
  assertNull(page2.getHeader("Transfer-Encoding"));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:URLConnectionTest.java

示例4: ping

import java.io.OutputStream; //导入方法依赖的package包/类
public static boolean ping(int port, final String expectedMsg) {
    boolean beaconExists = false;
    try {
        Socket socket = new Socket("localhost", port);
        final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        final OutputStream output = socket.getOutputStream();
        output.write("ping\n".getBytes());
        String response = reader.readLine();
        beaconExists = response.equals(expectedMsg);
        socket.close();
    }
    catch (Exception e) {
        Logger log = LoggerFactory.getLogger(ActiveAppPinger.class);
        if (log.isDebugEnabled()) {
            log.debug("Failed to connect to port " + port, e);
        }
    }
    return beaconExists;

}
 
开发者ID:mbari-media-management,项目名称:vars-annotation,代码行数:21,代码来源:ActiveAppPinger.java

示例5: copySkinFromAssets

import java.io.OutputStream; //导入方法依赖的package包/类
private String copySkinFromAssets(Context context, String name) {
    String skinPath = new File(SkinFileUtils.getSkinDir(context), name).getAbsolutePath();
    try {
        InputStream is = context.getAssets().open(
                SkinConstants.SKIN_DEPLOY_PATH + File.separator + name);
        OutputStream os = new FileOutputStream(skinPath);
        int byteCount;
        byte[] bytes = new byte[1024];
        while ((byteCount = is.read(bytes)) != -1) {
            os.write(bytes, 0, byteCount);
        }
        os.close();
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return skinPath;
}
 
开发者ID:ximsfei,项目名称:Android-skin-support,代码行数:19,代码来源:SkinAssetsLoader.java

示例6: encode

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Encode the CertificateVersion period in DER form to the stream.
 *
 * @param out the OutputStream to marshal the contents to.
 * @exception IOException on errors.
 */
public void encode(OutputStream out) throws IOException {
    // Nothing for default
    if (version == V1) {
        return;
    }
    DerOutputStream tmp = new DerOutputStream();
    tmp.putInteger(version);

    DerOutputStream seq = new DerOutputStream();
    seq.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)0),
              tmp);

    out.write(seq.toByteArray());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:CertificateVersion.java

示例7: writeUTF

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Writes a string to the specified DataOutput using UTF-8 encoding in a
 * machine-independent manner.
 * <p>
 * @param      str   a string to be written.
 * @param      out   destination to write to
 * @return     The number of bytes written out.
 * @exception  IOException  if an I/O error occurs.
 */
public static int writeUTF(String str,
                           OutputStream out) throws IOException {

    int strlen = str.length();
    int c,
        count  = 0;

    for (int i = 0; i < strlen; i++) {
        c = str.charAt(i);

        if (c >= 0x0001 && c <= 0x007F) {
            out.write(c);

            count++;
        } else if (c > 0x07FF) {
            out.write(0xE0 | ((c >> 12) & 0x0F));
            out.write(0x80 | ((c >> 6) & 0x3F));
            out.write(0x80 | ((c >> 0) & 0x3F));

            count += 3;
        } else {
            out.write(0xC0 | ((c >> 6) & 0x1F));
            out.write(0x80 | ((c >> 0) & 0x3F));

            count += 2;
        }
    }

    return count;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:40,代码来源:StringConverter.java

示例8: testReloadCorruptTrustStore

import java.io.OutputStream; //导入方法依赖的package包/类
@Test
public void testReloadCorruptTrustStore() throws Exception {
  KeyPair kp = generateKeyPair("RSA");
  cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA");
  cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA");
  String truststoreLocation = BASEDIR + "/testcorrupt.jks";
  createTrustStore(truststoreLocation, "password", "cert1", cert1);

  ReloadingX509TrustManager tm =
    new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10);
  try {
    tm.init();
    assertEquals(1, tm.getAcceptedIssuers().length);
    X509Certificate cert = tm.getAcceptedIssuers()[0];

    OutputStream os = new FileOutputStream(truststoreLocation);
    os.write(1);
    os.close();
    new File(truststoreLocation).setLastModified(System.currentTimeMillis() -
                                                 1000);

    // Wait so that the file modification time is different
    Thread.sleep((tm.getReloadInterval() + 200));

    assertEquals(1, tm.getAcceptedIssuers().length);
    assertEquals(cert, tm.getAcceptedIssuers()[0]);
  } finally {
    tm.destroy();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:TestReloadingX509TrustManager.java

示例9: copyBufferToStream

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Copy data from a buffer to an output stream. Does not update the position
 * in the buffer.
 * @param out the stream to write bytes to
 * @param in the buffer to read bytes from
 * @param offset the offset in the buffer (from the buffer's array offset)
 *      to start copying bytes from
 * @param length the number of bytes to copy
 */
public static void copyBufferToStream(OutputStream out, ByteBuffer in,
    int offset, int length) throws IOException {
  if (in.hasArray()) {
    out.write(in.array(), in.arrayOffset() + offset,
        length);
  } else {
    for (int i = 0; i < length; ++i) {
      out.write(in.get(offset + i));
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:ByteBufferUtils.java

示例10: print

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Print error list to output stream.
 * @param out SHOULD NOT set null.
 */
public void print(OutputStream out) throws IOException {
    if (out == null) {
        throw new NullPointerException("Output stream should be set first.");
    }

    for (MZTabError e : errorList) {
        out.write(e.toString().getBytes());
    }
}
 
开发者ID:nilshoffmann,项目名称:jmzTab-m,代码行数:14,代码来源:MZTabErrorList.java

示例11: copyStream

import java.io.OutputStream; //导入方法依赖的package包/类
static void copyStream(InputStream in, OutputStream out) throws IOException {
    byte[] buf = new byte[8192];
    int n = in.read(buf);
    while (n > 0) {
        out.write(buf, 0, n);
        n = in.read(buf);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestHelper.java

示例12: getStream

import java.io.OutputStream; //导入方法依赖的package包/类
@GET
@Path("stream")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public StreamingOutput getStream() {
	return new StreamingOutput() {
		@Override
		public void write(OutputStream output) throws IOException, WebApplicationException {
			output.write(new byte[] { 1, 2, 3 });
		}
	};
}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:12,代码来源:TestRestClient.java

示例13: encode

import java.io.OutputStream; //导入方法依赖的package包/类
/**
 * Write the extension to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to
 * @exception IOException on encoding errors
 */
public void encode(OutputStream out) throws IOException {
    DerOutputStream  tmp = new DerOutputStream();

    if (this.extensionValue == null) {
        this.extensionId = PKIXExtensions.InvalidityDate_Id;
        this.critical = false;
        encodeThis();
    }
    super.encode(tmp);
    out.write(tmp.toByteArray());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:InvalidityDateExtension.java

示例14: decodeAtom

import java.io.OutputStream; //导入方法依赖的package包/类
private void decodeAtom(PushbackInputStream paramPushbackInputStream, OutputStream paramOutputStream, int paramInt)
    throws IOException {
    int i;
    int j = -1;
    int k = -1;
    int m = -1;
    int n = -1;

    if (paramInt < 2) {
        throw new java.lang.ArrayStoreException("BASE64Decoder: Not enough bytes for an atom.");
    }
    do {
        i = paramPushbackInputStream.read();
        if (i == -1) {
            throw new RuntimeException();
        }
    } while ((i == 10) || (i == 13));
    this.decode_buffer[0] = (byte)i;

    i = readFully(paramPushbackInputStream, this.decode_buffer, 1, paramInt - 1);
    if (i == -1) {
        throw new RuntimeException();
    }

    if ((paramInt > 3) && (this.decode_buffer[3] == 61)) {
        paramInt = 3;
    }
    if ((paramInt > 2) && (this.decode_buffer[2] == 61)) {
        paramInt = 2;
    }
    switch (paramInt) {
    case 4:
        n = pem_convert_array[(this.decode_buffer[3] & 0xFF)];
    case 3:
        m = pem_convert_array[(this.decode_buffer[2] & 0xFF)];
    case 2:
        k = pem_convert_array[(this.decode_buffer[1] & 0xFF)];
        j = pem_convert_array[(this.decode_buffer[0] & 0xFF)];
    }

    switch (paramInt) {
    case 2:
        paramOutputStream.write((byte)(j << 2 & 0xFC | k >>> 4 & 0x3));
        break;
    case 3:
        paramOutputStream.write((byte)(j << 2 & 0xFC | k >>> 4 & 0x3));
        paramOutputStream.write((byte)(k << 4 & 0xF0 | m >>> 2 & 0xF));
        break;
    case 4:
        paramOutputStream.write((byte)(j << 2 & 0xFC | k >>> 4 & 0x3));
        paramOutputStream.write((byte)(k << 4 & 0xF0 | m >>> 2 & 0xF));
        paramOutputStream.write((byte)(m << 6 & 0xC0 | n & 0x3F));
    }
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:55,代码来源:BASE64Encoder.java

示例15: encodeExcessK

import java.io.OutputStream; //导入方法依赖的package包/类
public static void encodeExcessK(long value, OutputStream output) throws IOException {
    value ^= SIGN_MASK; // flip MSB (the sign bit)
    for (int bitsToShift = INITIAL_BITS_TO_SHIFT; bitsToShift >= 0; bitsToShift -= ONE_BYTE) {
        output.write((byte)(value >>> bitsToShift));
    }
}
 
开发者ID:npgall,项目名称:bitwise-tuples,代码行数:7,代码来源:ExcessKLongEncoder.java


注:本文中的java.io.OutputStream.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。