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


Java OutputStream类代码示例

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


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

示例1: createDataStream

import java.io.OutputStream; //导入依赖的package包/类
public OutputStream createDataStream()
{
    if (absDataFile.exists())
    {
        if (overwrite == false)
        {
            throw new ExporterException("Package data file " + absDataFile.getAbsolutePath() + " already exists.");
        }
        log("Warning: Overwriting existing package file " + absDataFile.getAbsolutePath());
        absDataFile.delete();
    }

    try
    {
        absDataFile.createNewFile();
        absDataStream = new FileOutputStream(absDataFile);
        return absDataStream;
    }
    catch(IOException e)
    {
        throw new ExporterException("Failed to create package file " + absDataFile.getAbsolutePath() + " due to " + e.getMessage());
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:FileExportPackageHandler.java

示例2: save

import java.io.OutputStream; //导入依赖的package包/类
public void save(OutputStream outStream, boolean sorted) throws IOException {
	if (!sorted) {
		save(outStream);
		return;
	}
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream, "UTF-8"));
    String aKey;
    Object aValue;
    TreeMap tm = new TreeMap(this);
    for (Iterator i = tm.keySet().iterator(); i.hasNext();) {
        aKey = (String) i.next();
        aValue = get(aKey);
        out.write(aKey + " = " + aValue);
        out.newLine();
    }
    out.flush();
    out.close();
}
 
开发者ID:ser316asu,项目名称:Dahlem_SER316,代码行数:19,代码来源:LoadableProperties.java

示例3: writeComment

import java.io.OutputStream; //导入依赖的package包/类
private void writeComment(OutputStream os, String comment) throws Exception {
	os.write(EXTENSION_INTRODUCER);
	os.write(COMMENT_EXTENSION_LABEL);
	byte[] commentBytes = comment.getBytes();
	int numBlocks = commentBytes.length/0xff;
	int leftOver = commentBytes.length % 0xff;
	int offset = 0;
	if(numBlocks > 0) {
		for(int i = 0; i < numBlocks; i++) {
			os.write(0xff);
			os.write(commentBytes, offset, 0xff);
			offset += 0xff;
		}
	}
	if(leftOver > 0) {
		os.write(leftOver);
		os.write(commentBytes, offset, leftOver);
	}
	os.write(0);
}
 
开发者ID:fatmanspanda,项目名称:SpriteAnimator,代码行数:21,代码来源:AnimatedGIFWriter.java

示例4: train

import java.io.OutputStream; //导入依赖的package包/类
public void train() {
    try {
        InputStreamFactory modelStream = new MarkableFileInputStreamFactory(
                new File(getClass().getClassLoader().getResource(TRAIN_INPUT).getFile())
        );
        final ObjectStream<String> lineStream = new PlainTextByLineStream(modelStream, "UTF-8");
        final ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream);

        final TrainingParameters mlParams = new TrainingParameters();
        mlParams.put(TrainingParameters.ITERATIONS_PARAM, 5000);
        mlParams.put(TrainingParameters.CUTOFF_PARAM, 5);

        final DoccatModel model = DocumentCategorizerME.train("en", sampleStream, mlParams, new DoccatFactory());
        final Path path = Paths.get(MODEL_OUTPUT);
        FileUtils.touch(path.toFile());
        try (OutputStream modelOut = new BufferedOutputStream(new FileOutputStream(path.toString()))) {
            model.serialize(modelOut);
        }
    } catch (Exception e) {
        LOGGER.error("an error occurred while training the sentiment analysis model", e);
        throw new IllegalStateException(e);
    }
}
 
开发者ID:kalnee,项目名称:trivor-nlp,代码行数:24,代码来源:SentimentTraining.java

示例5: saveChartAsPNG

import java.io.OutputStream; //导入依赖的package包/类
/**
 * Saves a chart to a file in PNG format.  This method allows you to pass 
 * in a {@link ChartRenderingInfo} object, to collect information about the 
 * chart dimensions/entities.  You will need this info if you want to 
 * create an HTML image map.
 *
 * @param file  the file (<code>null</code> not permitted).
 * @param chart  the chart (<code>null</code> not permitted).
 * @param width  the image width.
 * @param height  the image height.
 * @param info  the chart rendering info (<code>null</code> permitted).
 *
 * @throws IOException if there are any I/O errors.
 */
public static void saveChartAsPNG(File file, JFreeChart chart,
        int width, int height, ChartRenderingInfo info) 
    throws IOException {

    if (file == null) {
        throw new IllegalArgumentException("Null 'file' argument.");
    }
    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    try {
        ChartUtilities.writeChartAsPNG(out, chart, width, height, info);
    }
    finally {
        out.close();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:ChartUtilities.java

示例6: printCounts

import java.io.OutputStream; //导入依赖的package包/类
public void printCounts(OutputStream out, boolean deltas) {
	PrintStream pout = new PrintStream(out);

	Iterator<Key> j = countMap.keySet().iterator();
	while (j.hasNext()) {
		Key key = j.next();
		int count = countMap.get(key).intValue();

		if (count != 0) {
			pout.print(key + ":\t");
			if (deltas && count > 0)
				pout.print("+");
			pout.println(count);
		}
	}
	pout.flush();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:CountBugs.java

示例7: dispatchSBDExport

import java.io.OutputStream; //导入依赖的package包/类
/**
 * Generates the necessary files for the forms upload to the SeaBioData repository
 */
private void dispatchSBDExport() throws IOException {


    SharedPreferences settings = getSharedPreferences(getString(R.string.app_name), MODE_PRIVATE);

    if (!settings.contains(Utils.TAG_SBD_USERNAME)) {
        Toast.makeText(this, getString(R.string.sbd_username_missing_export), Toast.LENGTH_SHORT).show();
        return;
    }

    HashMap<String, ArrayList<FormInstance>> groupedInstances = new HashMap<>();
    for (FormInstance fi : currentItem.getLinkedForms()) {
        if (groupedInstances.containsKey(fi.getParent())) {
            groupedInstances.get(fi.getParent()).add(fi);
            continue;
        }

        ArrayList<FormInstance> newInstances = new ArrayList<>();
        newInstances.add(fi);
        groupedInstances.put(fi.getParent(), newInstances);
    }


    for (String key : groupedInstances.keySet()) {
        FormExportItem exportItem = new FormExportItem(groupedInstances.get(key), settings.getString(Utils.TAG_SBD_USERNAME, ""));
        File file = new File(Environment.getExternalStorageDirectory() + File.separator + key + "_" + new Date().toString() + ".json");

        if(file.createNewFile()) {
            OutputStream fo = new FileOutputStream(file);
            fo.write(new Gson().toJson(exportItem).getBytes());
            fo.close();
        }
    }

    Toast.makeText(getApplicationContext(), getString(R.string.sbd_dorms_exported_successfully), Toast.LENGTH_SHORT).show();
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:40,代码来源:FavoriteDetailsActivity.java

示例8: write

import java.io.OutputStream; //导入依赖的package包/类
/**
 * Writes a stream of bytes representing an audio file of the specified file type
 * to the output stream provided.  Some file types require that
 * the length be written into the file header; such files cannot be written from
 * start to finish unless the length is known in advance.  An attempt
 * to write a file of such a type will fail with an IOException if the length in
 * the audio file type is <code>AudioSystem.NOT_SPECIFIED</code>.
 *
 * @param stream the audio input stream containing audio data to be
 * written to the file
 * @param fileType the kind of audio file to write
 * @param out the stream to which the file data should be written
 * @return the number of bytes written to the output stream
 * @throws IOException if an input/output exception occurs
 * @throws IllegalArgumentException if the file type is not supported by
 * the system
 * @see #isFileTypeSupported
 * @see     #getAudioFileTypes
 */
public static int write(AudioInputStream stream, AudioFileFormat.Type fileType,
                        OutputStream out) throws IOException {

    List providers = getAudioFileWriters();
    int bytesWritten = 0;
    boolean flag = false;

    for(int i=0; i < providers.size(); i++) {
        AudioFileWriter writer = (AudioFileWriter) providers.get(i);
        try {
            bytesWritten = writer.write( stream, fileType, out ); // throws IOException
            flag = true;
            break;
        } catch (IllegalArgumentException e) {
            // thrown if this provider cannot write the sequence, try the next
            continue;
        }
    }
    if(!flag) {
        throw new IllegalArgumentException("could not write audio file: file type not supported: " + fileType);
    } else {
        return bytesWritten;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:44,代码来源:AudioSystem.java

示例9: writeTo

import java.io.OutputStream; //导入依赖的package包/类
@Override
public void writeTo(OutputStream out) throws IOException {
    // Begin the map/object/array/whatever exactly this is
    out.write(AmfType.MAP.getValue());

    // Write the "array size"
    Util.writeUnsignedInt32(out, properties.size());

    // Write key/value pairs in this object        
    for (Map.Entry<String, AmfData> entry : properties.entrySet()) {
        // The key must be a STRING type, and thus the "type-definition" byte is implied (not included in message)
        AmfString.writeStringTo(out, entry.getKey(), true);
        entry.getValue().writeTo(out);
    }

    // End the object        
    out.write(OBJECT_END_MARKER);
}
 
开发者ID:pedroSG94,项目名称:rtmp-rtsp-stream-client-java,代码行数:19,代码来源:AmfMap.java

示例10: saveXml

import java.io.OutputStream; //导入依赖的package包/类
private void saveXml(
        final OutputStream out) throws IOException {
    final PrintWriter writer =
            new PrintWriter(new OutputStreamWriter(out, ENCODING));
    
    writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.println("<files-list>");
    
    for (FileEntry entry: this) {
        if (entry.getFile().exists() && !entry.isMetaDataReady()) {
            entry.calculateMetaData();
        }
        
        writer.println("    " + entry.toXml());
    }
    
    writer.println("</files-list>");
    
    writer.flush();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:FilesList.java

示例11: getImage

import java.io.OutputStream; //导入依赖的package包/类
public void getImage(OutputStream outputStream, String plantId, String uploadID) {
        try {
            Document filterDoc = new Document();

            filterDoc.append("id", plantId);
            filterDoc.append("uploadID", uploadID);

            Iterator<Document> iter = plantCollection.find(filterDoc).iterator();

            Document plant = iter.next();
            String filePath = plant.getString("photoLocation");

//            String filePath = ".photos" + '/' + plantId + ".png";
            File file = new File(filePath);
            try {
                BufferedImage photo = ImageIO.read(file);
                ImageIO.write(photo,"JPEG",outputStream);
            } catch (IIOException e) {}

        }
        catch (IOException ioe) {
            ioe.printStackTrace();
            System.err.println("Could not write some Images to disk, exiting.");
        }
    }
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:26,代码来源:PlantController.java

示例12: execShellCmd

import java.io.OutputStream; //导入依赖的package包/类
/**
 * 执行shell命令
 *
 * @param cmd
 */
private void execShellCmd(String cmd) {

    try {
        // 申请获取root权限,这一步很重要,不然会没有作用
        Process process = Runtime.getRuntime().exec("su");
        // 获取输出流
        OutputStream outputStream = process.getOutputStream();
        DataOutputStream dataOutputStream = new DataOutputStream(
                outputStream);
        dataOutputStream.writeBytes(cmd);
        dataOutputStream.flush();
        dataOutputStream.close();
        outputStream.close();
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
 
开发者ID:yippeesoft,项目名称:NotifyTools,代码行数:23,代码来源:FloatView.java

示例13: testShowItIsPossibleToPassInBeansWrappedObject

import java.io.OutputStream; //导入依赖的package包/类
public void testShowItIsPossibleToPassInBeansWrappedObject() throws Exception {
    FileObject root = FileUtil.createMemoryFileSystem().getRoot();
    FileObject fo = FileUtil.createData(root, "simpleObject.txt");
    OutputStream os = fo.getOutputStream();
    String txt = "<#if (classInfo.getMethods().size() > 0) >The size is greater than 0.</#if>";
    os.write(txt.getBytes());
    os.close();       
    
    
    StringWriter w = new StringWriter();
                    
    Map<String,Object> parameters = Collections.<String,Object>singletonMap(
        "classInfo", BeansWrapper.getDefaultInstance().wrap(new ClassInfo())
    );
    apply(fo, w, parameters);
    assertEquals("The size is greater than 0.", w.toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ProcessorTest.java

示例14: initContents

import java.io.OutputStream; //导入依赖的package包/类
void initContents(OutputStream out) throws IOException {
    for (int i = 0; i < size; i++) {
        out.write(byteBuf);
    }
    out.write(new byte[4]); // add the 4 byte pad
    out.flush();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:InputStreamTests.java

示例15: createCompressionStream

import java.io.OutputStream; //导入依赖的package包/类
@Override
public synchronized OutputStream createCompressionStream(
    OutputStream downStream, Compressor compressor,
    int downStreamBufferSize) throws IOException {
  if (downStreamBufferSize > 0) {
    return new BufferedOutputStream(downStream, downStreamBufferSize);
  }

  return downStream;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:11,代码来源:Compression.java


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