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


Java Util.cleanup方法代码示例

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


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

示例1: getVideoComponent

import com.codename1.io.Util; //导入方法依赖的package包/类
@Override
public Component getVideoComponent() {
    if (component == null) {
        if(uri != null) {
            moviePlayerPeer = nativeInstance.createVideoComponent(uri, onCompletionCallbackId);
            nativeInstance.setNativeVideoControlsEmbedded(moviePlayerPeer, embedNativeControls);
            component = PeerComponent.create(new long[] { nativeInstance.getVideoViewPeer(moviePlayerPeer) });
        } else {
            try {
                byte[] data = toByteArray(stream);
                Util.cleanup(stream);
                moviePlayerPeer = nativeInstance.createVideoComponent(data, onCompletionCallbackId);
                component = PeerComponent.create(new long[] { nativeInstance.getVideoViewPeer(moviePlayerPeer) });
            } catch (IOException ex) {
                ex.printStackTrace();
                return new Label("Error loading video " + ex);
            }
        }
    }
    return component;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:22,代码来源:IOSImplementation.java

示例2: readResponse

import com.codename1.io.Util; //导入方法依赖的package包/类
protected void readResponse(InputStream input) throws IOException {
    //BufferedInputStream i = new BufferedInputStream(new InputStreamReader(input, ));
    BufferedInputStream i;
    if(input instanceof BufferedInputStream){
        i = (BufferedInputStream) input;
    }else{
        i = new BufferedInputStream(input);
    }
    i.setYield(-1);
    InputStreamReader reader = new InputStreamReader(i, "UTF-8");
    JSONParser.parse(reader, this);
    Util.cleanup(reader);
    if(stack.size() > 0){
        fireResponseListener(new NetworkEvent(this, stack.elementAt(0)));
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:FacebookRESTService.java

示例3: readResponse

import com.codename1.io.Util; //导入方法依赖的package包/类
protected void readResponse(InputStream input) throws IOException  {
    DataInputStream di = new DataInputStream(input);

    for(int iter = 0 ; iter  < objects.length ; iter++) {
        try {
            if(di.readBoolean()) {
                objects[iter].setLastModified(di.readLong());
                objects[iter].setValues((Hashtable)Util.readObject(di));
            }
            objects[iter].setStatus(CloudObject.STATUS_COMMITTED);
        } catch (IOException ex) {
            Log.e(ex);
        }
    }

    Util.cleanup(di);

    returnValue = RETURN_CODE_SUCCESS;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:20,代码来源:CloudStorage.java

示例4: getStorageEntrySize

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * Returns the size of the entry in bytes
 * @param name the entry name
 * @return the size
 */
public int getStorageEntrySize(String name) {
    long size = -1;
    try {
        InputStream i = createStorageInputStream(name);
        long val = i.skip(1000000);
        if(val > -1) {
            size = 0;
            while(val > -1) {
                size += val;
                val = i.skip(1000000);
            }
        }
        Util.cleanup(i);
    } catch(IOException err) {
        Log.e(err);
    }
    return (int)size;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:24,代码来源:CodenameOneImplementation.java

示例5: getImageData

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public byte[] getImageData() {
    if(data != null) {
        return data;
    }
    InputStream i = null;
    try {
        byte[] imageData = new byte[(int) FileSystemStorage.getInstance().getLength(fileName)];
        i = FileSystemStorage.getInstance().openInputStream(fileName);
        Util.readFully(i, imageData);
        if(keep) {
            data = imageData;
        }
        return imageData;
    } catch (IOException ex) {
        Log.e(ex);
        return null;
    } finally {
        Util.cleanup(i);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:24,代码来源:FileEncodedImage.java

示例6: createImage

import com.codename1.io.Util; //导入方法依赖的package包/类
public Object createImage(InputStream i) throws IOException {
    long ns = getNSData(i);
    if(ns > 0) {
        int[] wh = widthHeight;
        NativeImage n = new NativeImage("Image created from stream");
        n.peer = nativeInstance.createImageNSData(ns, wh);
        n.width = wh[0];
        n.height = wh[1];
        Util.cleanup(i);
        return n;
    }
    byte[] buffer = toByteArray(i);
    return createImage(buffer, 0, buffer.length);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:15,代码来源:IOSImplementation.java

示例7: play

import com.codename1.io.Util; //导入方法依赖的package包/类
@Override
public void play() {
    if(isVideo) {
        if(component == null && nativePlayer) {
            // Mass source of confusion.  If getVideoComponent() has been called, then
            // we can't use the native player.
            if(uri != null) {
                moviePlayerPeer = nativeInstance.createNativeVideoComponent(uri, onCompletionCallbackId);
            } else {
                try {
                    long val = getNSData(stream);
                    if(val > 0) {
                        moviePlayerPeer = nativeInstance.createNativeVideoComponentNSData(val, onCompletionCallbackId);
                        Util.cleanup(stream);
                    } else {
                        byte[] data = Util.readInputStream(stream);
                        Util.cleanup(stream);
                        moviePlayerPeer = nativeInstance.createNativeVideoComponent(data, onCompletionCallbackId);
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
            nativeInstance.showNativePlayerController(moviePlayerPeer);
            return;
        }
        if(moviePlayerPeer != 0) {
            nativeInstance.startVideoComponent(moviePlayerPeer);
        }
    } else {
        nativeInstance.playAudio(moviePlayerPeer);                
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:34,代码来源:IOSImplementation.java

示例8: capturePhoto

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * <p>Invokes the camera and takes a photo synchronously while blocking the EDT, the sample below
 * demonstrates a simple usage and applying a mask to the result</p>
 * <script src="https://gist.github.com/codenameone/b18c37dfcc7de752e0e6.js"></script>
 * <img src="https://www.codenameone.com/img/developer-guide/graphics-image-masking.png" alt="Picture after the capture was complete and the resulted image was rounded. The background was set to red so the rounding effect will be more noticeable" />
 * 
 * @param width the target width for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1
 * @param height the target height for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1
 * @return the photo file location or null if the user canceled
 */
public static String capturePhoto(int width, int height) {
    CallBack c = new CallBack();
    if("ios".equals(Display.getInstance().getPlatformName()) && (width != -1 || height != -1)) {
        // workaround for threading issues in iOS https://github.com/codenameone/CodenameOne/issues/2246
        capturePhoto(c);
        Display.getInstance().invokeAndBlock(c);
        if(c.url == null) {
            return null;
        }
        ImageIO scale = Display.getInstance().getImageIO();
        if(scale != null) {
            try {
                String path = c.url.substring(0, c.url.indexOf(".")) + "s" + c.url.substring(c.url.indexOf("."));
                OutputStream os = FileSystemStorage.getInstance().openOutputStream(path);
                scale.save(c.url, os, ImageIO.FORMAT_JPEG, width, height, 1);
                Util.cleanup(os);
                FileSystemStorage.getInstance().delete(c.url);
                return path;
            } catch (IOException ex) {
                Log.e(ex);
            }
        }
    } else {
        c.targetWidth = width;
        c.targetHeight = height;
        capturePhoto(c);
        Display.getInstance().invokeAndBlock(c);
    }
    return c.url;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:41,代码来源:Capture.java

示例9: createAnonymous

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * Creates an anonymous persona that will be unique in the cloud, NEVER logout an anonymous user!
 * @return false in case login failed e.g. due to bad network connection
 */
public static boolean createAnonymous() {
    if(instance == null) {
        getCurrentPersona();
    }
    ConnectionRequest login = new ConnectionRequest();
    login.setPost(true);
    login.setUrl(CloudStorage.SERVER_URL + "/objStoreUser");
    login.addArgument("pk", Display.getInstance().getProperty("package_name", null));
    login.addArgument("bb", Display.getInstance().getProperty("built_by_user", null));
    NetworkManager.getInstance().addToQueueAndWait(login);
    if(login.getResposeCode() != 200) {
        return false;
    }
    
    ByteArrayInputStream bi = new ByteArrayInputStream(login.getResponseData());
    DataInputStream di = new DataInputStream(bi);
    
    if(instance == null) {
        instance = new CloudPersona();
    } 
    try {
        instance.persona = di.readUTF();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    Preferences.set("CN1Persona", instance.persona);
    Preferences.set("CN1PersonaAnonymous", true);
    
    Util.cleanup(di);
    
    return true;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:37,代码来源:CloudPersona.java

示例10: createFromImage

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * Converts an image to encoded image
 * @param i image
 * @param jpeg true to try and set jpeg, will do a best effort but this isn't guaranteed
 * @return an encoded image or null
 */
public static EncodedImage createFromImage(Image i, boolean jpeg) {
    if(i instanceof EncodedImage) {
        return ((EncodedImage)i);
    }
    ImageIO io = ImageIO.getImageIO();
    if(io != null) {
        String format;
        if(jpeg) {
            if(!io.isFormatSupported(ImageIO.FORMAT_JPEG)) {
                format = ImageIO.FORMAT_PNG; 
            } else {
                format = ImageIO.FORMAT_JPEG; 
            }
        } else {
            if(!io.isFormatSupported(ImageIO.FORMAT_PNG)) {
                format = ImageIO.FORMAT_JPEG;
            } else {
                format = ImageIO.FORMAT_PNG;
            }
        }
        try {
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            io.save(i, bo, format, 0.9f);
            EncodedImage enc = EncodedImage.create(bo.toByteArray());
            Util.cleanup(bo);
            enc.width = i.getWidth();
            enc.height = i.getHeight();
            if(format == ImageIO.FORMAT_JPEG) {
                enc.opaque = true;
                enc.opaqueChecked = true;
            }
            enc.cache = Display.getInstance().createSoftWeakRef(i);
            return enc;
        } catch(IOException err) {
            Log.e(err);
        }            
    }
    return null;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:46,代码来源:EncodedImage.java

示例11: createFromRGB

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * Tries to create an encoded image from RGB which is more efficient,
 * however if this fails it falls back to regular RGB image. This method
 * is slower than creating an RGB image (not to be confused with the RGBImage class which is
 * something ENTIRELY different!).
 * 
 * @param argb an argb array
 * @param width the width for the image
 * @param height the height for the image
 * @param jpeg uses jpeg format internally which is opaque and could be faster/smaller
 * @return an image which we hope is an encoded image
 */
public static Image createFromRGB(int[] argb, int width, int height, boolean jpeg) {
    Image i = Image.createImage(argb, width, height);
    ImageIO io = ImageIO.getImageIO();
    if(io != null) {
        String format;
        if(jpeg) {
            if(!io.isFormatSupported(ImageIO.FORMAT_JPEG)) {
                return i;
            }
            format = ImageIO.FORMAT_JPEG;
        } else {
            if(!io.isFormatSupported(ImageIO.FORMAT_PNG)) {
                return i;
            }
            format = ImageIO.FORMAT_PNG;
        }
        try {
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            io.save(i, bo, format, 0.9f);
            EncodedImage enc = EncodedImage.create(bo.toByteArray());
            Util.cleanup(bo);
            enc.width = width;
            enc.height = height;
            if(jpeg) {
                enc.opaque = true;
                enc.opaqueChecked = true;
            }
            enc.cache = Display.getInstance().createSoftWeakRef(i);
            return enc;
        } catch(IOException err) {
            Log.e(err);
        }
        
    }
    return i;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:49,代码来源:EncodedImage.java

示例12: installTar

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * Installs a tar file from the build server into the file system storage so it can be used with respect for hierarchy
 */
public void installTar() throws IOException {
    String p = Preferences.get("cn1$InstallKey", null);
    String buildKey = Display.getInstance().getProperty("build_key", null);
    if(p == null || !p.equals(buildKey)) {
        FileSystemStorage fs = FileSystemStorage.getInstance();
        String tardir = fs.getAppHomePath() + "cn1html/";
        fs.mkdir(tardir);
        TarInputStream is = new TarInputStream(Display.getInstance().getResourceAsStream(getClass(), "/html.tar"));
        
        TarEntry t = is.getNextEntry();
        byte[] data = new byte[8192];
        while(t != null) {
            String name = t.getName();
            if(t.isDirectory()) {
                fs.mkdir(tardir + name);
            } else {
                String path = tardir + name;
                String dir = path.substring(0,path.lastIndexOf('/'));
                if (!fs.exists(dir)) {
                    mkdirs(fs, dir);
                }

                OutputStream os = fs.openOutputStream(tardir + name);
                int count;
                while((count = is.read(data)) != -1) {
                    os.write(data, 0, count);
                }

                os.close();
            }
            
            t = is.getNextEntry();
        }
        
        Util.cleanup(is);
        Preferences.set("cn1$InstallKey", buildKey);
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:42,代码来源:CodenameOneImplementation.java

示例13: getStack

import com.codename1.io.Util; //导入方法依赖的package包/类
/**
 * Prints the stack trace matching the given stack
 */
public String getStack(Throwable t) {
    try {
        StringBuffer b = new StringBuffer();
        int size;
        int[] s = (int[])exceptionStack.get(t);
        if(s == null) {
            s = stack;
            size = stackPointer;
        } else {
            size = s.length;
        }
        String[] stk = new String[size];
        
        InputStream inp = Display.getInstance().getResourceAsStream(getClass(), "/methodData.dat");
        if(inp == null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            t.printStackTrace(pw);
            String str = sw.toString();
            Util.cleanup(sw);
            return str;
        }
        DataInputStream di = new DataInputStream(inp);
        int totalAmount = di.readInt();
        String lastClass = "";
        for(int x = 0 ; x < totalAmount ; x++) {
            String current = di.readUTF();
            if(current.indexOf('.') > -1) {
                lastClass = current;
            } else {
                for(int iter = 0 ; iter < size ; iter++) {
                    if(s[iter] == x + 1) {
                        stk[iter] = lastClass + "." + current;
                    }
                }
            }
        }
        for(int iter = size - 1 ; iter >= 0 ; iter--) {
            b.append("at ");
            b.append(stk[iter]);
            b.append("\n");
        }
        return b.toString();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return "Failed in stack generation for " + t;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:52,代码来源:CodenameOneThread.java

示例14: toByteArray

import com.codename1.io.Util; //导入方法依赖的package包/类
public byte[] toByteArray() throws IOException {
    if (isBackedByFile()) {
        NSFileInputStream fis = null;
        
        fis = new NSFileInputStream(getFilePath());
        byte[] out = Util.readInputStream(fis);
        
        Util.cleanup(fis);
        return out;
        
        
        
    } else {
        return buf.toByteArray();
    }
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:17,代码来源:IOSImplementation.java

示例15: ShareForm

import com.codename1.io.Util; //导入方法依赖的package包/类
ShareForm(final Form contacts, String title, String toShare, String txt, String image, 
        ActionListener share) {
    setTitle(title);
    setLayout(new BorderLayout());
    this.message.setText(txt);
    post.addActionListener(share);
    if(toShare != null){
        this.to.setText(toShare);
        addComponent(BorderLayout.NORTH, to);
    }
    if(image == null){
        addComponent(BorderLayout.CENTER, message);
    }else{
        Container body = new Container(new BorderLayout());
        if(txt != null && txt.length() > 0){
            body.addComponent(BorderLayout.SOUTH, message);
        }
        Label im = new Label();
        ImageIO scale = ImageIO.getImageIO();
        if(scale != null){
            InputStream is = null;
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            try {
                is = FileSystemStorage.getInstance().openInputStream(image);
                scale.save(is, os, ImageIO.FORMAT_JPEG, 200, 200, 1);
                Image i = Image.createImage(os.toByteArray(), 0, os.toByteArray().length);
                im.setIcon(i);
            } catch (IOException ex) {
                //if failed to open the image file simply put the path as text
                im.setText(image);                   
            }finally{
                Util.cleanup(os);
                Util.cleanup(is);                                    
            }
        }else{
            im.setText(image);
        }
        body.addComponent(BorderLayout.CENTER, im);            
        addComponent(BorderLayout.CENTER, body);        
    }
    addComponent(BorderLayout.SOUTH, post);
    Command back = new Command("Back") {

        public void actionPerformed(ActionEvent evt) {
            
            contacts.showBack();
        }
    };
    addCommand(back);
    setBackCommand(back);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:52,代码来源:ShareForm.java


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